1.在MyDLL(MFC DLL)项目中的MyDLL.cpp中的片段:// 唯一的 CMyDLLApp 对象CMyDLLApp theApp;__declspec(dllexport) void SK(CString str)
{
AfxMessageBox("Hello"+str);
}2.在MyPrj(MFC程序)项目中调用方法如下:void CMyPrjDlg::OnBnClickedButton1()
{
// TODO: 在此添加控件通知处理程序代码
HINSTANCE  DLL;
DLL=::LoadLibrary("mydll.dll");
FARPROC  FUN;
FUN=GetProcAddress(DLL,"show"); typedef void (FAR __cdecl *MyClass)(CString str);
MyClass show;
show =(MyClass)GetProcAddress(DLL,"SK");
CString strs("Fine");
show(strs);             //********在这里出错**********///
}////////////////////////////////////////////////////////
程序可以编译通过,但是运行到最后一句的时候
show(strs);
提示错误信息为:
MyPrj.exe 中的 0x00000000 处未处理的异常:0xC0000005: 读取位置 0x00000000 时发生访问冲突 。
本例主要是想学习如何在只有一个dll文件的情况下,动态调用DLL。请问,该如何解决???应该不可能非要加Def/lib文件的吧??谢谢先~~~

解决方案 »

  1.   

    lib文件就不需要了
    应该调试跟踪以下,看:show是否为0(多数是为0)
      

  2.   

    我没加任何文件.照楼上说的,我加了一行
    if(!show)
    {
    AfxMessageBox("失败");
    return;
    }
    结果按按钮,就提示“失败”
    Dumpbin 的结果为:
    Dump of file mydll.dllFile Type: DLL  Section contains the following exports for MyDLL.dll    00000000 characteristics
        3F5336EE time date stamp Mon Sep 01 20:09:18 2003
            0.00 version
               1 ordinal base
               2 number of functions
               2 number of names    ordinal hint RVA      name          1    0 000112B7 ?SK@@YAXV?$CStringT@DV?$StrTraitMFC@DV?$ChTraitsCRT@D@
    ATL@@@@@ATL@@@Z
              2    1 00011285 ?show@MyClass@@QAEXV?$CStringT@DV?$StrTraitMFC@DV?$ChT
    raitsCRT@D@ATL@@@@@ATL@@@Z  Summary        4000 .data
            2000 .idata
            3000 .rdata
            1000 .reloc
            1000 .rsrc
            F000 .text
           10000 .textbss难道我的DLL有问题吗?那么我的DLL问题出在那里?