How to call a DLL Dialog resource

   If we want to use a Dialog box resource in a DLL.As begining,I should tell you some details about AFX_MANAGE_STATE macro.

AFX_MANAGE_STATE( AFX_MODULE_STATE* pModuleStatepModuleState is pointer to an AFX_MODULE_STATE module.We can make use of this macro so that we can protect an exported function in a DLL.When this macro is invoked,pModuleState is the effective module state for the reminder of the immediate containing scope.Upon leaving the scope,the previous effective module state will be automatically restored.The AFX_MODULE_STATE contains  global data for module.That is,the portion of module state is pushed or popped.By default,MFC uses the resource handle of the main application to load resource template like dialog something like that.If we have a exported function in a DLL,such as one that launches

a dialob box in the DLL,this template is actually stored in the DLL module. We need to switch

the module state for the correct handle to be used.We can do this by adding the following code to the beginning of the function:

 

CTestApp theApp;   //The Object of main application. 

void ShowDialog()  //An exported function in DLL
{   
 AFX_MANAGE_STATE(AfxGetStaticModuleState()); // Switch the state of module

                                                                            //This swaps the current module state  with the state returned from AfxGetStaticModuleState until the end of the current scope

 

 CTestDlg dlg;
 dlg.DoModal();     //call the dialog box resource.
}

The next,we should import DLL library file to the source files of our work project like this:

   (...cpp)

 #pragma comment(lib, "test.lib")

 Addheader file TestDialog.h to our work project,declare exported function in this source files like this:

  void showDlg();

and then we can do this by calling this exported function like following code:

  void CDemoDlg::OnTest()
{
 ShowDialog();
}

 

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

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

EXPORTS
 ShowDialog

 The above mentioned is a simple instance of application.

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值