开发者

Show dialog from MFC DLL

开发者 https://www.devze.com 2023-03-13 05:23 出处:网络
I loaded the form but only buttons without functions HMODULE hModule = LoadLibrary(L\"Tools.dll\"); if (hModule != NULL)

I loaded the form but only buttons without functions

HMODULE hModule = LoadLibrary(L"Tools.dll");

if (hModule != NULL)
{
    AfxSetResourceHandle(hModule);
    CDialog dgl(MAKEINTRESOURCE(199), NULL);
    dgl.DoModal(); 
}

so how I can load a full function of form a开发者_StackOverflownd I don't have the DLL source code


To show Dialog box from MFC dll , like scenario - you have exported function in DLL and from that function you call DoModel().This template actually stored in DLL module.You need to switch module state for current handle to be used.You can do this by using :

AFX_MANAGE_STATE(AfxGetStaticModuleState());

AFX_MODULE_STATE AfxGetStaticModuleState()

->The AFX_MODULE_STATE structure contains global data for the module,that is the portion of the module state that is pushed or popped.

IN DLL code will be like this :

AFX_MANAGE_STATE(AfxGetStaticModuleState());
CMyDlg objMyDlg;
iRet = objMyDlg.DoModal(); 


This is possible only if you are sure that dialog class implementation is MFC based and the class is exported from Tools.dll. You can try inspect your .dll with Dependency Walker utility.
Please note the compiler mangles constructor name. This is what I got for the following declaration.

class __declspec(dllexport) TestDialog : public CDialog
{
public:
    TestDialog()
        :CDialog(10)
    {

    }
};

Mangled constructor name: ??_7TestDialog@@6B@

Probably you will be able to recreate dialog class header based on the results of your inspection. You should also make sure you have the same version of MFC both for Tools.dll and your application.

0

精彩评论

暂无评论...
验证码 换一张
取 消