void TestFunc (void *param) {printf ("\n\tcall global function%s\n", param);} void *getclassfuncaddr (...) {DWORD Address;__asm{lea eax,addressmov edx, [Ebp + 8]mov [eax], Edx}return (void *) address;} void *callfunc (void *pfn, void *pthis, void *param) {if (pthis! = NULL) {unsigned long dwthis = (unsigned long) pthis; Typede F void* (__fastcall *memfunc) (void *,int, void*); The//__fastcall invocation method first passes two DWORD parameters (ECX and edx)//typedef void* (__thiscall *MEMFUNC) (void *, void*),//__thiscall call passing ECX/*typedef void* (__stdcall *memfunc) (void *),//__stdcall call mode, this method is prepared This pointer __asm mov ecx, dwthis; */Return Reinterpret_cast<memfunc> (PFN) (pthis, 0, param);} else{typedef void * (*normalfunc) (void*); return reinterpret_cast<normalfunc> (PFN) (param);} Class Ctest{public:void Simplefunc (char *str) {printf ("\n\tcall member function%s\n", str);} void Simplecall (char *p) {Callfunc (Getclassfuncaddr (&ctest::simplefunc), this, (void*) p);}}; int _tmain (int argc, _tchar* argv[]) {CTest *pthis = new CTest (); char *str = "Test str"; void *addr = Getclassfuncaddr (&ctest::simplecall); Callfunc (addr, pthis, void* ) str); Callfunc (&testfunc, NULL, (void*) str); return 0;}
One thing to add: The above are all based on the format of the called function
void *func (void*);
In addition, for virtual functions of classes, this method is not applicable, because when you call a virtual function, you need to determine the virtual function table of the class, where I do not do too much analysis
As it is now, I feel it is enough for me to write thread classes;)
Actual operation depends on the specific format
If I say something wrong, please let me know;)
C + + calls global functions and class member functions