How to call a DLL Dialog resource
2010-11-22 10:24
507 查看
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* pModuleState ) pModuleState 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.
AFX_MANAGE_STATE( AFX_MODULE_STATE* pModuleState ) pModuleState 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.
相关文章推荐
- How to load a dll resource dialog box at an application Dialog box (怎么在一个应用程序对话框动态加载DLL里的资源对话框)
- How to Load Dialog From a Resource DLL?
- How to call DLL and LIB files (SDK)
- how to use dialog
- How to do peer-to-peer video call?
- 通过WebBrowser中的脚本调用Delphi自定义的方法(How to call Delphi code from scripts running in a TWebBrowser)
- How to terminate call
- How to use an external dll file in VisualStudio project
- How to build mscorlib.dll with visual studio
- How to call Android contacts list?
- How To Get Lync 2010 Call and Conversation History On Lync Mobile Device
- HOWTO: How to Provide Your Own DllMain in an MFC Regular DLL
- How to Delete From or Add Resource to OCR in Oracle Clusterware (文档 ID 1069369.1)
- How to Write a Killer Software Testing QA Resume That Will Turn Into an Interview Call
- How to create a DLL library in C and then use it with C#
- How to drag a dialog box derived from DHtmlDialog ?
- How to release IPC resource after oracle Instance crash/abort
- How to find public key token for a .NET DLL or assembly
- How to load the specified mscordacwks.dll for managed debugging when multiple .NET runtime are loaded in one process
- How to use an external dll file in VisualStudio project