各位大牛,我刚学关于DLL方面的知识,现在碰到个问题,请教下:
我调用一个DLL文件,文件中有如下的接口
extern "C" _declspec(dllexport)  bool CreateInstance(void** pInterface)
我怎么调用,我新建了一个基于对话框的项目,谢谢

解决方案 »

  1.   

    声明 extern "C" _declspec(dllimport) bool CreateInstance(void** pInterface)
    然后把编译DLL的时候生成的Lib文件包含到工程中
    然后直接用就行了
      

  2.   

    从方便的角度,用隐式调用的方式,先声明一下:
    extern "C" _declspec(dllimport) bool CreateInstance(void** pInterface);
    然后直接调用CreateInstance就行了.不过在编译时要用到LIB文件
      

  3.   

    //创建网络服务实例(返回服务指针)
    extern "C" _declspec(dllexport)  bool CreateInstance(void** pInterface)
    {
    _pLT = new CLTCtrl(); 
    *pInterface=static_cast<DV*>(_pLT);
    return true;
    }
    上面是导出函数,我写的函数如下void CdLGDlg::OnBnClickedOk()
    {
    HINSTANCE   hDllInst   =   LoadLibrary( "LT.dll");
    if(hDllInst == NULL)
    MessageBox("失败!");
    else if(hDllInst)   
           {  
            //    这里不知道该怎写了                     
            }
    OnOK();
    }
      

  4.   

    如果你想用显式调用的话,这样写:
    typedef bool (*lpFunc)(void** );
    lpFunc f;
    f=(lpFunc)GetProcAddress(hDllInst,_T("CreateInstance"));
    f(....);//调用函数;
      

  5.   

            static HINSTANCE hinstDLL; 
    typedef bool (*inshook)(void**);
    inshook instkbhook;
    hinstDLL = LoadLibrary((LPCTSTR)"你的dll.dll");
    if(hinstDLL)
    {
    instkbhook = (inshook)GetProcAddress(hinstDLL,_T"YXPersonalize"); 
    instkbhook(要下的参数);
    }
    else
    {
    ::AfxMessageBox ("load Dll 失败");
    }
    FreeLibrary(hinstDLL);
      

  6.   

    typedef bool(* CI)(void**);
    CI pCreateInstance = (CI)GetProcAddress(hDllInst, "CreateInstance");
    if (pCreateInstance != NULL)
    {
        ...
    }