我建立了一个导出类的DLL,现在我想动态载入DLL,那么怎么和这个导出类的DLL建立连接呢? 如果是导出函数,载入函数地址就可以了.但导出类总不能导出类的地址吧? 高手帮帮我.

解决方案 »

  1.   

    向你使用系统dll中的函数一样,没有任何的区别!
    只不过你必须在你的工程中包含你得到处类的头文件!还应包括你在客户端调用到的资源的id!
    在project--->setting-->link指明你的dll的连接库的yourdll.lib的位置而已!
      

  2.   

    TO: psusong(我心飞扬)你所说的我都知道,但我要的是动态连接.
      

  3.   

    导出类*.h中:class AFX_EXT_CLASS CYou
    在你的程序中必须包含导出类的头文件。
      

  4.   

    但我要的是动态连接导出类的DLL.
      

  5.   

    试一试COM
    在DLL里面建立一个一个类
    提供一个导出函数
    比如CreateObject,在这个函数里面创建一个类的对象,返回给应用程序就行了
    :)
      

  6.   

    连接!!!!!!!!!!!!!
    连接!!!!!!!!!!!!!
    连接!!!!!!!!!!!!!
    连接!!!!!!!!!!!!!
    我不要LIB库.
      

  7.   

    DLL中:
    extern "C" __declspec(dllexport) void __stdcall NewObj(void** ppObj);
    void __stdcall NewObj(void** ppObj)
    {
        CDLLClass* pObj=new CDLLClass();
        *ppObj=pObj; 
    }client中:typedef void __declspec(dllimport) MyDLLClass(void **);
    MyDLLClass *Load1; CDLLClass* pDLLClass;
     HINSTANCE Dll = LoadLibrary("yourdll");
      if (Dll)
        {
            // Get the address of the function.
            Load1 = (MyDLLClass *)GetProcAddress(Dll, "NewObj");
            // Make sure we have the address then call the function.
            if (Load1)
                Load1((void**)&pDLLClass);
            else
                ShowMessage(SysErrorMessage(GetLastError()));        // After we're done with the Dll we have to free it.
           //FreeLibrary(Dll);
        }
    现在你可以取得指向该类的指针pDLLClass.