65.9K
CodeProject is changing. Read more.
Home

Get a Pointer to a Memberfunction

starIconemptyStarIconemptyStarIconemptyStarIconemptyStarIcon

1.00/5 (1 vote)

Feb 23, 2011

CPOL
viewsIcon

19888

This shows you how to cast a Pointer to a Memberfunction to any Pointer Type you whish.

In my actual project, I needed a way to get a void* to a Memberfunction but the compiler would just throw cast errors at me. So I just used the way in which the compiler implemented these calls.
void* p;
__asm MOV eax,offset MyClass::MyFunction
__asm MOV p,eax
or as Macro:
#define MEMBERPTR(f,v) __asm MOV eax,offset f \
                         __asm MOV v,eax
This will give you the correct address of virtual and normal member functions. Tested on MSVC++ 2008. Might be different on other Compilers!