WillieBotha
Programmer
Hi,
I have a little problem here everytime I try to get a return value for a function after I loaded the library and got the PRocAddress I get the following error :
Debug Error !
Program : "c:\blah"
Module:
File: i368\chkesp.c"
Line: 42
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.
My code is the following (Mind the confusion):
#include "stdafx.h"
#include <malloc.h>
typedef LPCSTR (CALLBACK* LPFNDLLFUNC1)(LPCSTR);
typedef long (CALLBACK* LPFNDLLFUNC2)(long Test);
int APIENTRY WinMain(HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPSTR lpCmdLine,
int nCmdShow)
{
LPFNDLLFUNC1 lpfnDllGetMakes;
LPFNDLLFUNC2 lpfnDlltest;// Function pointer
LPCSTR cstrReturnVal,
cstrParam1=",";
long intReturnVal,
intParam1=0;
HINSTANCE MEADDLLADDR;
LPCSTR GetMakes="GetMakes";
LPCSTR test="test";
LPCTSTR MeadDLL="c:\\meadtest\\c++ apps\\meaddll\\mead_dll.dll";
// TODO: Place code here.
MEADDLLADDR=LoadLibrary(MeadDLL);
// lpfnDllGetMakes=(LPFNDLLFUNC1)GetProcAddress(MEADDLLADDR, // handle to DLL module
//GetMakes); // name of function
lpfnDlltest=(LPFNDLLFUNC2)GetProcAddress(MEADDLLADDR, // handle to DLL module
test); // name of function
malloc(sizeof(lpfnDlltest));
cstrParam1=",";
if (!lpfnDlltest) {
FreeLibrary(MEADDLLADDR);
// AfxMessageBox("Error occured while trying to load MeadDLL",mbOK,-1);
return 1;
}
else
{
intReturnVal=lpfnDlltest(intParam1);
}
if (!lpfnDllGetMakes) {
FreeLibrary(MEADDLLADDR);
// AfxMessageBox("Error occured while trying to load MeadDLL",mbOK,-1);
return 1;
}
else
{
cstrReturnVal=lpfnDllGetMakes(cstrParam1);
}
return 0;
}
Willie Botha
Programmer
Mead & McGrouther
South-Africa
I have a little problem here everytime I try to get a return value for a function after I loaded the library and got the PRocAddress I get the following error :
Debug Error !
Program : "c:\blah"
Module:
File: i368\chkesp.c"
Line: 42
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.
My code is the following (Mind the confusion):
#include "stdafx.h"
#include <malloc.h>
typedef LPCSTR (CALLBACK* LPFNDLLFUNC1)(LPCSTR);
typedef long (CALLBACK* LPFNDLLFUNC2)(long Test);
int APIENTRY WinMain(HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPSTR lpCmdLine,
int nCmdShow)
{
LPFNDLLFUNC1 lpfnDllGetMakes;
LPFNDLLFUNC2 lpfnDlltest;// Function pointer
LPCSTR cstrReturnVal,
cstrParam1=",";
long intReturnVal,
intParam1=0;
HINSTANCE MEADDLLADDR;
LPCSTR GetMakes="GetMakes";
LPCSTR test="test";
LPCTSTR MeadDLL="c:\\meadtest\\c++ apps\\meaddll\\mead_dll.dll";
// TODO: Place code here.
MEADDLLADDR=LoadLibrary(MeadDLL);
// lpfnDllGetMakes=(LPFNDLLFUNC1)GetProcAddress(MEADDLLADDR, // handle to DLL module
//GetMakes); // name of function
lpfnDlltest=(LPFNDLLFUNC2)GetProcAddress(MEADDLLADDR, // handle to DLL module
test); // name of function
malloc(sizeof(lpfnDlltest));
cstrParam1=",";
if (!lpfnDlltest) {
FreeLibrary(MEADDLLADDR);
// AfxMessageBox("Error occured while trying to load MeadDLL",mbOK,-1);
return 1;
}
else
{
intReturnVal=lpfnDlltest(intParam1);
}
if (!lpfnDllGetMakes) {
FreeLibrary(MEADDLLADDR);
// AfxMessageBox("Error occured while trying to load MeadDLL",mbOK,-1);
return 1;
}
else
{
cstrReturnVal=lpfnDllGetMakes(cstrParam1);
}
return 0;
}
Willie Botha
Programmer
Mead & McGrouther
South-Africa