|
-
Jan 5th, 2003, 02:30 PM
#1
Thread Starter
<?="Moderator"?>
dll calling problems
ive created a DLL and im trying to call it but it keeps giving me these errors.
Run-Time Check Failure #0 - The value of ESP was not properly saved across a function call. This is usually a result of calling a function declared with one calling convention with a function pointer declared with a different calling convention.
heres my code
Code:
#include <windows.h>
typedef void (*MSGBOX)(char*,int);
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow)
{
HINSTANCE hDLL;
MSGBOX msgProc;
hDLL = LoadLibrary("dlltest.dll");
if(hDLL!=NULL)
{
msgProc = (MSGBOX)GetProcAddress(hDLL,"msgbox");
if(msgProc!=NULL)
(*msgProc)("Batman its worked!", MB_OK);
FreeLibrary(hDLL);
}
return 0;
}
cheers
-
Jan 5th, 2003, 03:11 PM
#2
I guess the function in the DLL looks like
void WINAPI msgbox(char * str, int i)
{
// ...
}
right?
Could be APIENTRY, CALLBACK or __stdcall instead of WINAPI, whatever.
All the buzzt
 CornedBee
"Writing specifications is like writing a novel. Writing code is like writing poetry."
- Anonymous, published by Raymond Chen
Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.
-
Jan 5th, 2003, 03:15 PM
#3
Thread Starter
<?="Moderator"?>
in the dll its,
Code:
#include <windows.h>
void __stdcall msgbox(char * cMsg, int i){
MessageBox(NULL,cMsg,i);
}
the function runs, its just that afterwards it comes up with the error.
thnx
-
Jan 5th, 2003, 03:22 PM
#4
typedef void (__stdcall *MSGBOX)(char*,int);
As the error message said, the problem was that the function in the DLL is a __stdcall, while the function pointer (which has no convention keyword) is assumed to be __cdecl. These two calling conventions are incompatible. The solution is to explicitly declare the function pointer to point to a __stdcall function, see above.
All the buzzt
 CornedBee
"Writing specifications is like writing a novel. Writing code is like writing poetry."
- Anonymous, published by Raymond Chen
Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.
-
Jan 5th, 2003, 03:22 PM
#5
BTW
MessageBox(NULL,cMsg,i);
Does this work? The WinAPI MessageBox takes 4 parameters.
All the buzzt
 CornedBee
"Writing specifications is like writing a novel. Writing code is like writing poetry."
- Anonymous, published by Raymond Chen
Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.
-
Jan 5th, 2003, 03:30 PM
#6
Thread Starter
<?="Moderator"?>
MessageBox(NULL,cMsg,i); doesn't work, i just forgot to put the title in.
Cheers for the help
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|