Click to See Complete Forum and Search --> : Question about GetProcAddress


Pechi
July 28th, 2003, 09:12 PM
My Code...(LoadLibrary and Get ASPI Enter).....

HINSTANCE hinstWNASPI32;
hinstWNASPI32=LoadLibrary("WNASPI32");
if(!hinstWNASPI32)
{/*LoadLibrary Success....*/}
BOOL(*pfnGetASPI32Buffer)(PASPI32BUFF);
pfnGetASPI32Buffer=GetProcAddress(hinstWNASPI32,"GetASPI32Buffer");

But, I Compiling have Error:
--------------------Configuration: x1 - Win32 Debug--------------------
Compiling...
x1.cpp
c:\documents and settings\administrator\®à_±\x1\x1.cpp(332) : error C2440: '=' : cannot convert from 'int (__stdcall *)(void)' to 'int (__cdecl *)(ASPI32BUFF *)'
This conversion requires a reinterpret_cast, a C-style cast or function-style cast
Error executing cl.exe.

x1.exe - 1 error(s), 0 warning(s)


Have anyone can tell me how to fix this error?
and could you give me a Example ??
thanks.

:(

Paul McKenzie
July 28th, 2003, 09:27 PM
a) You cast the return type of GetProcAddress to your function pointer type. Also use typedef's. If you did a search on CodeGuru for "GetProcAddress" you would have found many examples.

b) You may have to change your function declaration to __stdcall. The reason is that the GetASPI32Buffer function may process the parameters to the function differently than the 'C' way (which is __cdecl). You will know this if your program crashes with an error stating that you are calling with the wrong calling convention and that "ESP could not be saved"

typedef BOOL (*FUNC)(PASPI32BUFF);
//...
FUNC pfnGetASPI32Buffer;
pfnGetASPI32Buffer = (FUNC)GetProcAddress(hinstWNASPI32,"GetASPI32Buffer");

Regards,

Paul McKenzie

Pechi
July 28th, 2003, 11:03 PM
Originally posted by Paul McKenzie
a) You cast the return type of GetProcAddress to your function pointer type. Also use typedef's. If you did a search on CodeGuru for "GetProcAddress" you would have found many examples.

b) You may have to change your function declaration to __stdcall. The reason is that the GetASPI32Buffer function may process the parameters to the function differently than the 'C' way (which is __cdecl). You will know this if your program crashes with an error stating that you are calling with the wrong calling convention and that "ESP could not be saved"

typedef BOOL (*FUNC)(PASPI32BUFF);
//...
FUNC pfnGetASPI32Buffer;
pfnGetASPI32Buffer = (FUNC)GetProcAddress(hinstWNASPI32,"GetASPI32Buffer");

Regards,

Paul McKenzie

thanks Paul McKenzie. ^_^