我写了一个Dialog,想将它包起来给别人使用,如何做?我建立一个 MFC DLL 动态链接库。
首先在动态链接库中加入一个对话框,就这个对话框,我想将它export出去,如何做呢?(不是在一个函数里调用对话框,再将 结果返回!)
(使用者要能够使用如下代码:MyDllDlg dlg;dlg.DoModal();......)

解决方案 »

  1.   

    extern "C" __declspec(dllexport) void XXXdlg()
    {   
    CXXXDlg dlg;
    dlg.DoModal();
    }
      

  2.   

    不是!我要 外部可以直接引用这个dlg类
      

  3.   

    试试
    class AFX_EXT_CLASS myDlg:public CDialog
    {}
    导出myDlg类。
    我用这种方法导出过普通类,CDialog派生类不一定能用。
      

  4.   

    在DLLMain中保留DLL的句柄到一个全局变量中
    HINSTANCE  gThisDLLInstance=NULL;extern "C" int APIENTRY
    DllMain(HINSTANCE hInstance, DWORD dwReason, LPVOID lpReserved)
    {
    // Remove this if you use lpReserved
    UNREFERENCED_PARAMETER(lpReserved); if (dwReason == DLL_PROCESS_ATTACH)
    {
    TRACE0("ZH2DZ.DLL Initializing!\n");

    // Extension DLL one-time initialization
    if (!AfxInitExtensionModule(ZH2DZDLL, hInstance))
    return 0; // Insert this DLL into the resource chain
    // NOTE: If this Extension DLL is being implicitly linked to by
    //  an MFC Regular DLL (such as an ActiveX Control)
    //  instead of an MFC application, then you will want to
    //  remove this line from DllMain and put it in a separate
    //  function exported from this Extension DLL.  The Regular DLL
    //  that uses this Extension DLL should then explicitly call that
    //  function to initialize this Extension DLL.  Otherwise,
    //  the CDynLinkLibrary object will not be attached to the
    //  Regular DLL's resource chain, and serious problems will
    //  result. new CDynLinkLibrary(ZH2DZDLL);
    gThisDLLInstance=hInstance;///此处保留DLL的句柄
    }
    else if (dwReason == DLL_PROCESS_DETACH)
    {
    TRACE0("ZH2DZ.DLL Terminating!\n");
    // Terminate the library before destructors are called
    AfxTermExtensionModule(ZH2DZDLL);
    }
    return 1;   // ok
    }
    //该类切换当前的资源句柄
    class CLoadDllResource
    {
    public:
    CLoadDllResource()
    {
    ::AfxSetResourceHandle(gThisDLLInstance);
    }
    ~CLoadDllResource()
    {
    ::AfxSetResourceHandle(::AfxGetInstanceHandle());
    }
    };extern "C" __declspec(dllexport) void XXXdlg()
    {   
             CLoadDllResource r;
    CXXXDlg dlg;
    dlg.DoModal();
    }
      

  5.   

    when process status is DLL_PROCESS_ATTACH
    AFX_MANAGE_STATE(AfxGetStaticModuleState( ));
    then export the dialog class,try it!!