⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 dialog_in_extdll.shtml.htm

📁 mfc资料集合5
💻 HTM
字号:
<HTML>
<HEAD>
   <META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=iso-8859-1">
   <META NAME="Author" CONTENT="Zafir Anjum">
   <TITLE>DLL - Export dialogs in MFC Extension DLLs</TITLE>
</HEAD>
<body background="../fancyhome/back.gif" tppabs="http://www.codeguru.com/fancyhome/back.gif" bgcolor="#FFFFFF" link="#B50029" vlink="#8E2323" alink="#FF0000">
<table WIDTH="100%">
<tr WIDTH="100%">
<td><td>
</tr>
</table>


<CENTER>
<H3>
<FONT COLOR="#AOAO99">Export dialogs in MFC Extension DLLs</FONT></H3></CENTER>
<HR>




This article was contributed by <A HREF="mailto:aleitner@usa.net">Andreas Leitner</A>.



  <P>
   It seems to be quite easy to export dialogs from mfc-extension dll's. Just export the corresponding class with AFX_EXT_CLASS and your done. If you do so with an application and a dll you create from scratch you probably even will succeed. But if you insert more and more resources in both the application and the dll, you will get some serious bugs. Here is the reason:
  </P>
  <P>
   The regular way to identify a specific resource is its ID. This is an integer constant defined by the resource editor. Now say you have got a resource (which is a string) called ID_MY_TEXT.
  
<PRE><TT><FONT COLOR="#990000">  
	CString strText;
	strText.LoadString( ID_MY_TEXT );
	afxDump << strText;
</FONT></TT></PRE>

<P>Code like this prints the resource-string into the debug window. Sometimes you may get a wrong text and this happens only if the text is in a mfc-extension-dll (mfc-ext-dll). The reason for this error lies in the way the application gets a resource. Since both the application and the dll can have a resource file, IDs can be the same for different resources. (Which is very likely because the VC resource editor starts numbering the IDs at a certain value for each module.)
  </P>
  <P>
   As you may guess the order the application searches for a resource is first in your application and afterwards in your dll(s) (and finally in the mfc-resources). We need to change the search order for resources.
  </P>
  <P>
   There is another article on this site which deals with dialog exports from DLL's. But that (as far as I have tested) works only in regular-mfc-dlls.
  </P>
  <P>
   I wrote a class that (with a little change in the dll main source file and the dialog) will enable you to freely call your dialog from wherever you want. Like:
  </P>
<PRE><TT><FONT COLOR="#990000">  
CMyApp::OnDLLDialog()
{
    CDLLDialog dlg;
    dlg.DoModal();
}
</FONT></TT></PRE>

<P>As you see there is no need for an export function (which would not be very OO).
  </P>
  <P>
   I wrote a simple class that sets the resource handle of the dll at its construction and sets back the previous handle at its destruction.
  </P>
  <P>Here it is:

<PRE><TT><FONT COLOR="#990000">
/////////////////////////////////////////////////////////////////////////////////////////////
// File ExtDllState.h
//////////////////////////////////////////////////////////////////////////////////////////// 
#ifndef __EXTDLLSTATE_H__
#define __EXTDLLSTATE_H__
 
class CEXTDLLState
{
public:

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -