void CCardDlg::OnButton1() 
{
int fMin;
HINSTANCE hIn;
// 创建一个新的函数指针数据类型
typedef int(MINTYPE)(char*,char*);
MINTYPE*pMin=0;
// 载入FindMin.dll
VERIFY(hIn=::LoadLibrary("mydll.dll"));
// 取得FindMin()函数的地址
   ??? VERIFY(pMin=(MINTYPE*)::GetProcAddress((HMODULE)hIn, "mydll"));
// 测试动态链接库的FindMin()函数
      
       /* char a[10];
char b[1024]; strcpy(a,"aaaaaaa");
strcpy(b,"this is start test"); fMin=(*pMin)(a,b);
// 显示测试结果
CString str;
str.Format("The minimum of %s and %s is %d", a,b,fMin);
AfxMessageBox(str);
// 卸载DLL
        */
FreeLibrary(hIn);
}在打???号的那句出错,出错信息为:
---------------------------
Microsoft Visual C++ Debug Library
---------------------------
Debug Assertion Failed!Program: C:\Card\Debug\Card.exe
File: C:\Card\CardDlg.cpp
Line: 183For information on how your program can cause an assertion
failure, see the Visual C++ documentation on asserts.(Press Retry to debug the application)
---------------------------
终止(A)   重试(R)   忽略(I)   
---------------------------到底为什么呢?

解决方案 »

  1.   

    你这样定义:
    typedef int (* MINTYPE)(char*,char*);
    MINTYPE pMin
    ???那句
    VERIFY(pMin=(MINTYPE)GetProcAddress(hIn, "mydll"));
      

  2.   

    你的 DLL 里面没有 mydll 这个函数。因为C++的DLL函数通常都被输出成类似 _mydll@@48576@347974235 这样的怪名字。
    所以C++的DLL一般都是静态调用的;
    pMin=(MINTYPE)GetProcAddress(hIn, "mydll")这是动态调用方法只能调C风格的DLL.
    当然,你如果有本事把DLL中_mydll@@48576@3479这种怪名字找出来,动态调用同样可以哦
      

  3.   

    Use dumpbin tool to find the entry point
      

  4.   

    Make use you did export "mydll"
    make a def file:
    LIBRARY MyDllEXPORTS
    mydll
    ////////////