What is the ESP, I need help
Her my little Code, but I don't know why it isn't work ;-(
// DLL:
extern "C" void __declspec (dllexport) Get_Func(int* i)
{
*i=99;
}
//Main-PRG:
CMyProg::OpenDLL()
{
HINSTANCE hDll;
typedef void (__stdcall *LPFNDLLFUNC1)(i*);
LPFNDLLFUNC1 lpGet_Func;
hDLL=LoadLibrary ("Test.DLL");
lpGet_Func= (LPFNDLLFUNC1)::GetProcAddress(hDLL,_T("Get_Func"));
if (lpGet_Func!=NULL)
{
int i;
lpGet_Func(&i);
// Now i must be 99 but I've got the ERROR
}
FreeLibrary (hDLL);
}
ERROR:
Debug Error!
The value of ESP was not properly saved across a function call. This is....
Re: What is the ESP, I need help
Get rid of "__stdcall" from your typedef and it should fix the problem.
The reason this is happening is because you're exporting the DLL function using the default calling convention (which is __cdecl). But you're calling it as if it used the __stdcall convention.
Cheers!
Alvaro
Re: What is the ESP, I need help
Alvaro is correct.
FYI - ESP is the Extended Stack Pointer.
Since you specified _stdcall, the callee (your DLL function) is expected
to clean up the stack prior to returning which means restoring it to the
value it had just before the function was called.