能正常运行,关闭主程序时出现如下错误:
Debug Error!Program:H:\myvccode\test\LoadMydll\Debug\LoadMydll.exe
Module:
File:i386\chkesp.c
Line:42The 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.dll导出函数如下:extern "C" _declspec (dllexport) void Firstload(char * Address,int ilen)
{
AFX_MANAGE_STATE(AfxGetStaticModuleState());
extern char * strAddress =Address;
extern int iblocklen = ilen;
Address = strAddress;
ilen = iblocklen;
mydlg.DoModal();
}调用程序如下:
HINSTANCE dllinstance;dllinstance=::LoadLibrary("mydll");if(dllinstance==NULL)
AfxMessageBox("can't open dll file");
else
{
typedef void (WINAPI *MYLOAD)(char * Address,int ilen); MYLOAD myload;
myload = (MYLOAD)GetProcAddress(dllinstance,"Firstload"); if(myload == NULL)
AfxMessageBox("can't find function");
else
{
myload("C:\\800x600.bmp",50);
}
}
FreeLibrary(dllinstance);
Debug Error!Program:H:\myvccode\test\LoadMydll\Debug\LoadMydll.exe
Module:
File:i386\chkesp.c
Line:42The 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.dll导出函数如下:extern "C" _declspec (dllexport) void Firstload(char * Address,int ilen)
{
AFX_MANAGE_STATE(AfxGetStaticModuleState());
extern char * strAddress =Address;
extern int iblocklen = ilen;
Address = strAddress;
ilen = iblocklen;
mydlg.DoModal();
}调用程序如下:
HINSTANCE dllinstance;dllinstance=::LoadLibrary("mydll");if(dllinstance==NULL)
AfxMessageBox("can't open dll file");
else
{
typedef void (WINAPI *MYLOAD)(char * Address,int ilen); MYLOAD myload;
myload = (MYLOAD)GetProcAddress(dllinstance,"Firstload"); if(myload == NULL)
AfxMessageBox("can't find function");
else
{
myload("C:\\800x600.bmp",50);
}
}
FreeLibrary(dllinstance);
mydlg定義在你的函數里面.
extern "C" _declspec (dllexport) void Firstload(char * Address,int ilen)
{
AFX_MANAGE_STATE(AfxGetStaticModuleState());
extern char * strAddress =Address;
extern int iblocklen = ilen;
Address = strAddress;
ilen = iblocklen;
CYouDlg mydlg(ID_DIALOG); ///注意加句.
mydlg.DoModal();
}
改成typedef void (FAR _cdecl *MYLOAD)(char * Address,int ilen);就没问题了。或者改成 typedef void (MYLOAD)(char * Address,int ilen); MYLOAD *myload;
myload = (MYLOAD*)GetProcAddress(dllinstance,"Firstload");
这样也可以。仍然感谢二位的帮助。谢谢!