1,extern "C" __declspec(dllexport) void ShowDlg(char* pfilepath)
{
AFX_MANAGE_STATE(AfxGetStaticModuleState());
CDlg dlg;
dlg.DoModal();// AfxMessageBox("filepath");
}2, char* pfilepath="C:\\test.h";
typedef void (FAR WINAPI * TESTDLL)(char*);
HINSTANCE hmod;
hmod = ::LoadLibrary ("H:\\VM\\3DViewer\\test_dll_dlg2\\Debug\\test_dll_dlg2.dll");
if(hmod==NULL)
{
AfxMessageBox("Fail");
}
TESTDLL lpproc;
lpproc = (TESTDLL)GetProcAddress (hmod,"ShowDlg");
if(lpproc!=(TESTDLL)NULL)
(*lpproc)(pfilepath);
FreeLibrary(hmod);错误:我测试参数已经传过去了,可是好像在测试程序退出时弹出错误:
File:i386\chkesp.c
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 funtion pointer declared with a different
calling convention.这是什么错误啊?怎么搞定啊?向大家请教!!!

解决方案 »

  1.   

    在你的DLL中有对话框资源,在你使用完了CDlg这后再调用FreeLibrary(hmod);功能
      

  2.   

    我是在最后才调用FreeLibrary(hmod)的啊!
      

  3.   

    你是在那最后,你放HINSTANCE hmod;在你的CMYApp类中,在你的InitInstance中用LoadLibrary在你的ExitInstance中调用FreeLibrary(hmod);
      

  4.   

    我是在一个按钮中实现上述动态加载dll传参数和动态卸载啊!我不想扩大作用域啊
      

  5.   

    你不使用FreeLibrary(hmod)有没有问题,
      

  6.   

    不使用extern "C",或在DLL定义中加_stdcall看看,我看错了好像不是FreeLibrary释放的问题
      

  7.   

    有可能是堆栈出了问题,可能是函数压栈和退栈的顺序不对。你不参数去掉,看看有没有问题,void ShowDlg()。如果是的话,看看你的工程属性,project-->setting-->c++->code generation-->calling convention, 是__stdcall,还是__cdcel.
      

  8.   

    是_stdcall和_cdcel问题。
    看看你的调用和声明是否一致。最好都用_stdcall。
    extern "C" __declspec(dllexport) void WINAPI ShowDlg(char* pfilepath)
    调用也用WINAPI。