Archived

This topic is now archived and is closed to further replies.

MatrixCubed

GetProcAddress woes

Recommended Posts

I have a function in a DLL defined as follows ... DWORD DLLFunction(DWORD val1, DWORD val2, DWORD* params ); ... So I''ve defined a function pointer to read from it ... DWORD (*lpDLLFunction)(DWORD val1, DWORD val2, DWORD* params ); ... but when I call the following ... lpDLLFunction = GetProcAddress(hLibrary, "DLLFunction"); .. I get the following error ... error C2440: ''='' : cannot convert from ''unsigned long (__stdcall *)(void)'' to ''unsigned long (__stdcall *)(unsigned long,unsigned long,long *)'' I''m not really sure what to do here. Should the function pointed be another type? Do I need to specify preprocessor directives? Any assistance is greatly appreciated. MatrixCubed
http://MatrixCubed.cjb.net

Share this post


Link to post
Share on other sites
Try this:

typedef unsigned long (*PFNDLLFunction)(DWORD, DWORD, DWORD *);

PFNDLLFunction lpDLLFunction = NULL;

lpDLLFunction = (PFNDLLFunction)GetProcAddress(hLibrary, "DLLFunction");

Note: that PFNDLLFunction is already a pointer to a function, so you don''t have to add a ''*'' to it.

-Brannon

Share this post


Link to post
Share on other sites
Oh yeah, I forgot to say that you always have to cast the result from GetProcAddress() to the proper function pointer type. Just in case this looked like a hack to make the compiler shutup. It is, but it''s one you have to use =).


-Brannon

Share this post


Link to post
Share on other sites