我在一个按钮的单击事件中是这样写的:
unsigned short i=1;
char pBuf[100];
memset(pBuf,0,sizeof(pBuf));
CString str;
char pqh[3]="01";
char pkh[3]="05";
HINSTANCE hInst;
hInst = LoadLibrary("icDllwd.dll");
if(hInst==NULL) AfxMessageBox("can't open dll file");
typedef bool (*ReadBlank)(int port, char * s1, char * s2, char * s3);//bool strchar(char *h)
ReadBlank add = (ReadBlank)GetProcAddress(hInst,"_ReadBlank@16");
if (!add)
{
MessageBox("失败!");
return;
}
else
{
if(add(i,pqh,pkh,pBuf))
{
str=pBuf;
MessageBox(str);
}
else
{
MessageBox("没成功!");
}
}
ReadBlank这个函数在DLL是这这样的:
extern "C" __declspec(dllexport) BOOL __stdcall ReadBlank(int port,char * s1,char * s2,char * s3)
我运行时出现
Debug Error!
File :i386/chkesp.c
line:42
The valuse 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 .
谢谢!