简体   繁体   English

显示来自 MFC DLL 的对话框

[英]Show dialog from MFC DLL

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 and I don't have the DLL source code所以我怎么能加载一个完整的 function 表格,我没有 DLL 源代码

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: 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通过使用:

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. -> The AFX_MODULE_STATE结构包含模块的全局数据,即模块 state 被推送或弹出的部分。

IN DLL code will be like this:在 DLL 代码将是这样的:

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.仅当您确定对话框 class 实现是基于 MFC 并且 class 是从 Tools.Z06416233E2AB4C593321. You can try inspect your.dll with Dependency Walker utility.您可以尝试使用Dependency Walker实用程序检查 your.dll。
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@损坏的构造函数名称:??_7TestDialog@@6B@

Probably you will be able to recreate dialog class header based on the results of your inspection.可能您将能够根据您的检查结果重新创建对话框 class header。 You should also make sure you have the same version of MFC both for Tools.dll and your application.您还应该确保 Tools.dll 和您的应用程序的 MFC 版本相同。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM