棘手问题:如何在两个以上的类里调用dll中定义的函数?只能在一个类里调用两个以上报错如下:
DealCenter.obj : error LNK2005: "class CString  (__cdecl* FormatDate)(double,int)" (?FormatDate@@3P6A?AVCString@@NH@ZA) already defined in CorpAreaView.obj
JoinCarView.obj : error LNK2005: "class CString  (__cdecl* FormatDate)(double,int)" (?FormatDate@@3P6A?AVCString@@NH@ZA) already defined in CorpAreaView.obj
StdAfx.obj : error LNK2005: "class CString  (__cdecl* FormatDate)(double,int)" (?FormatDate@@3P6A?AVCString@@NH@ZA) already defined in CorpAreaView.obj
StdAfx.obj : error LNK2005: "struct HINSTANCE__ *  gDS" (?gDS@@3PAUHINSTANCE__@@A) already defined in DealCenter.obj
e:/project/apps/cdc.exe : fatal error LNK1169: one or more multiply defined symbols found
Error executing link.exe.高手帮忙阿?谢谢
谢谢

解决方案 »

  1.   

    一个动态加载Dll的处理过程如下,例如,你的Dll里有如下函数:
    void theFunction();你可以这样调用:type void (*FUNCTYPE)();
    FUNCTYPE g_theFunc=NULL;  //定义一个全局的函数指针变量。
    如果你的别的CPP里也要调这个函数,则在那个CPP里声明
    extern FUNCTYPE g_theFunc;然后:
    HMODULE hMod = LoadLibray( "MYDLL.dll" );
    g_theFunc = (FUNCTYPE)GetProcAddress( hMod, "theFunction" );
    if( g_theFunc )
    {
        g_theFunc(); //这里调用了DLL里的函数。
    }
    签名:jmcooler