引用dll中的函数时,用loadlibrary动态加载,指明绝对路径,用完了再freelibrary不知有否帮助

解决方案 »

  1.   

    这是我写的一个测试程序,2个DLL有相同的方法,在不同条件下调用。
    与你这个有类似的地方。{
             //Load Dll
    HMODULE hModule1,hModule2;
    hModule1 = LoadLibrary("test01.dll");
    hModule2 = LoadLibrary("test02.dll");
    if(!(hModule1&&hModule2))
    {
    AfxMessageBox("Load Dll Error!");
    return;
    } FUNCTYPE *pFunc1,*pFunc2;
    long n1,n2;
    long x ;
    pFunc1 = (FUNCTYPE*)GetProcAddress(hModule1,"TestProc");
    pFunc2 = (FUNCTYPE*)GetProcAddress(hModule2,"TestProc");
    if(!(pFunc1&&pFunc2))
    {
    //Free Dll
    ::FreeLibrary(hModule1);
    ::FreeLibrary(hModule2);
    AfxMessageBox("Get Process Address Error!");
    return;
    }
    x =999;
    n1 = (*pFunc1)(x);
    n2 = (*pFunc2)(x); char szOut[1024];
    memset(szOut,0,1024);
    sprintf(szOut,"%d,%d",n1,n2);
    AfxMessageBox(szOut); //Free Dll
    ::FreeLibrary(hModule1);
    ::FreeLibrary(hModule2);
    }
      

  2.   

    补充:定义dll中的函数TestProc:typedef long FUNCTYPE(long);
    extern "C" _declspec(dllexport) long TestProc(long n);
      

  3.   

    cqa:您好!
         非常感谢你的指导,我用不是不同dll中函数名相同的情况,而是我们编写的dll文件名与系统中的一个dll文件名相同的情况,而且我这做了这后导致了系统dll中的一部分函数不好用了,并不是全部不好用。