Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Calling DLL's from Visual C++ 6

Status
Not open for further replies.

WillieBotha

Programmer
Jun 20, 2001
5
0
0
ZA
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=&quot;,&quot;;
long intReturnVal,
intParam1=0;
HINSTANCE MEADDLLADDR;
LPCSTR GetMakes=&quot;GetMakes&quot;;
LPCSTR test=&quot;test&quot;;
LPCTSTR MeadDLL=&quot;c:\\meadtest\\c++ apps\\meaddll\\mead_dll.dll&quot;;
// 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=&quot;,&quot;;


if (!lpfnDlltest) {
FreeLibrary(MEADDLLADDR);
// AfxMessageBox(&quot;Error occured while trying to load MeadDLL&quot;,mbOK,-1);
return 1;

}
else
{
intReturnVal=lpfnDlltest(intParam1);

}

if (!lpfnDllGetMakes) {
FreeLibrary(MEADDLLADDR);
// AfxMessageBox(&quot;Error occured while trying to load MeadDLL&quot;,mbOK,-1);
return 1;

}
else
{
cstrReturnVal=lpfnDllGetMakes(cstrParam1);
}


return 0;
}
Willie Botha
Programmer
Mead & McGrouther
South-Africa
 
I think your Dll functions &quot;GetMakes&quot; and &quot;test&quot; are declared without specification _stdcall (CALLBACK).
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top