1

I am trying to create a (32-bit) DLL to inject into a target process.

My DLL should call a function inside the original process. So far nothing special, however the target function is using the thiscall calling convention.

I am trying to use my own fake class object. The method does nothing more then setting a few variables in this class object.

My attempt:

class HashClass
{
public:
    byte data[1024];
    LPVOID HashFunc(float, char, char);
};

typedef LPVOID (HashClass::*HASHFUNC)(float, char, char);

HASHFUNC *HashFunc = (HASHFUNC *) 0xD34DB33F;

void CallHashFunction()
{
   HashClass *hashClass = new HashClass();
   (hashClass->*HashFunc)(1.0f, 'a', 'b');  // Getting an error here
}

What is the best and easiest method for this?

Errors i am getting:

Error   1   error C2297: '.*' : illegal, right operand has type 'HASHFUNC *'
        2   IntelliSense: expression must have pointer-to-member type
  • consider what is "this" in a call - it's just another parameter, so you can HashFunc(hashClass, 1.0f, 'a', 'b'). The callee won't know the difference. – peter ferrie Mar 30 '16 at 15:27
  • I guess this would work with 64-bit applications. However with 32-bit there clearly is a difference between stdcall and thiscall calling convention. – eKKiM Mar 30 '16 at 15:30
  • 2
    that depends entirely on your compiler. GCC does it like cdecl. MSVC is stdcall but with __asm mov ecx, hashClass first. – peter ferrie Mar 30 '16 at 15:34
1

What error you get?

Try something like this:

class HashClass
{
public:
    byte data[1024];
    LPVOID HashFunc(float, char, char);
};

typedef LPVOID (HashClass::*HASHFUNC)(float, char, char);

 HASHFUNC *HashFunc = (HASHFUNC *) 0xD34DB33F;

 void CallHashFunction()
 {
    HashClass *hashClass = new HashClass();
    (*hashClass.*HashFunc)(1.0f, 'a', 'b');
 }
  • Updated the code and the errors i get. – eKKiM Mar 30 '16 at 14:44

Not the answer you're looking for? Browse other questions tagged or ask your own question.