Joe Matt Joe Matt - 1 year ago 75
C++ Question

What is the correct function pointer for an unsigned WINAPI function?

I've a function declared in this way:

unsigned WINAPI searchSTR(void *j);

And I need a pointer to this function. My idea was:

unsigned (*pointerF) (void*);
pointerF = &searchSTR;

But there is an error:

"1 error C2440: '=' : cannot convert from 'unsigned int (__stdcall *)(void *)'
to 'unsigned int (__cdecl *)(void *)' ".

I tried other sintax, but nothing seems correct, he doesn't like the word WINAPI.

Can you suggest me the correct syntax? Maybe it is easy but I am blocked ! Thanks to all

Answer Source

The WINAPI macro expands to __stdcall, which is a different calling convention from the default __cdecl. You need to mark your function pointer with the calling convention to use:

unsigned (WINAPI *pointerF) (void*)
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download