How to load a dll resource dialog box at an application Dialog box (怎么在一个应用程序对话框动态加载DLL里的资源对话框)

本文介绍了如何在MFC应用程序中动态加载DLL资源对话框。通过创建DLL资源对话框文件,定义全局应用程序对象并设置接口函数showDlg,实现了DLL对话框的调用。在主应用程序中,通过LoadLibrary和GetProcAddress函数找到并执行DLL中的showDlg函数,从而显示DLL资源对话框。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

   This afternoon,although  I have had  a little out of my mind.I am so excited because I learned a lot MFC intellectal points from a bit topic. I have handled how to load a dll resource at an application Dialog box successfully.Before this,I checked it out for a long time, I read papers about Dll resource dialog box and how to call it dynamicaly.I can do this as following code to bring about purpose:

    The Dll dialob box define like this:

By default,I think you have created a dll dll resource dialog box file,so here,I just only add portion of main code.

 

    #include "myDllResource.h"         //the dll resource dialog box header file.
   CDllResourceApp theApp;             //the global object of application procedure.
void  __stdcall showDlg()                // call dll dialog box function .
{
 AFX_MANAGE_STATE(AfxGetStaticModuleState());
 myDllResource dlg;
 UINT iResult = dlg.DoModal();
}

 

showDlg function is an interface function and you must define it in the main  application procedure. You also need to create *.def file as exported function (showDlg) template like this:

  ; DllResource.def : Declares the module parameters for the DLL.

LIBRARY      "DllResource"
DESCRIPTION  'DllResource Windows Dynamic Link Library'

EXPORTS
    ; Explicit exports can go here
 showDlg

This file,you must define  it at dll application file containing source files of DLL. Next,you should create a dialog box (exe) and add a button on the dialog Form to call dll resource dialog box.I know you a very smart to create this.the main part of code like this:

     void CDemoDllDlg::OnCall()
{
 // TODO: Add your control notification handler code here
 typedef void (__stdcall *lpFun)(void);          //function pointer
    HINSTANCE hDll; //DLL handle(句柄)
 CString dllPath;
 CString resPath;
 char fullPath[MAX_PATH];
 ZeroMemory(fullPath,sizeof(fullPath));
 ::GetModuleFileName(AfxGetInstanceHandle(),fullPath,MAX_PATH);
 resPath.Format(_T("%s"),fullPath);
 resPath = resPath.Left(resPath.ReverseFind('//')+1);
 dllPath = resPath + _T("DllResource.dll");
    hDll = LoadLibrary(dllPath);
    if (hDll == (HINSTANCE)HINSTANCE_ERROR)
 {
  MessageBox("Loading DLL failed!");
 }

     lpFun pShowDlg;
  pShowDlg = (lpFun)GetProcAddress(hDll,"showDlg");
    if (NULL==pShowDlg)
 {
      MessageBox("Searching DLL function failed!");
 }
    pShowDlg(); //call a dll resource dialog box by a function adddress.

}

I am so tired today~~!

  

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值