1

I don't even know how to properly word this, but I'll try my best to explain it in code:

typedef void( *ExampleFn )( PVOID p1, PVOID p2, PVOID p3 );

struct Example
{
    void ExampleFunction( PVOID p1, PVOID p2, PVOID p3 )
    {
        // do something with Example's members
    }
};

Example example;
ExampleFn exampleFn = example.ExampleFunction;

So, I get this error:

Error C2440 '=': cannot convert from 'void (__thiscall Example::* )(PVOID,PVOID,PVOID)' to 'ExampleFn'

I understand the problem, Example::ExampleFunction is a __thiscall and ExampleFn is not, but how can I go about this?

How to have a Example object with a ExampleFn-like function in it that can use that object's members?

  • Supposed that you can use one of the `PVOID` parameters to pass user defined data, the marked duplicate's answers offer a way how it can be done. – πάντα ῥεῖ Oct 22 '15 at 15:37

1 Answers1

1

You need to define youre function-pointer correctly. It's a member-function pointer, so it needs to look like this:

typedef void(Example::*ExampleFn )( PVOID p1, PVOID p2, PVOID p3 );

The __thiscall is just the call-convention of member-functions, so that's set automatically.

You defined a pointer to a plain-function so it doesn't work. That doesn't concern the call-convetion really.