Reputation: 2409
in my header api file there is this. (not my code)
typedef void (WINAPI *PIN_FUNC)(char*,LPVOID);
__PINLIB__ int WINAPI PIN_GetNumeric(int m_id,char * Message,PIN_FUNC func,LPVOID Param);
and at one point I had it working by doing this in my code
static void WINAPI Pinpad_Handle(char *buf, LPVOID pParam);
void WINAPI PinpadHelper::Pinpad_Handle( char *buf, LPVOID pParam){...}
but i get the distinct feeling that I'm doing it wrong. And being new to VC++ I don't know how to fix it. The tutorial that i read on typedef mainly talked about variables and abstraction and so forth (which I understood that side of it) I thought that I could do this
static PIN_FUNC PinpadEvent(char* buffer, LPVOID pParam);
but that throws a error in Visual Studio. How do i properly do this? or did I have it right the first time?
Upvotes: 0
Views: 65
Reputation: 942119
You were doing it right originally. PIN_FUNC is just a C function pointer declaration. You must write a C function with the exact same signature as the function pointer. Which you did, nothing wrong with your original code. The compiler would have generated an error if you tried to assign the function pointer and you got the function signature wrong. Lots of programmers make the mistake of casting the error away, that's a fatal mistake that bombs badly at runtime. So never do that.
Not so sure what you tried to do in the last snippet. If you want to declare your own variable that stores the function pointer then that needs to look like this:
static PIN_FUNC PinpadEvent;
Of course it still needs to be assigned. Check your favorite C language programming book about function pointers if you are still confused.
Upvotes: 2