国产一级a片免费看高清,亚洲熟女中文字幕在线视频,黄三级高清在线播放,免费黄色视频在线看

打開APP
userphoto
未登錄

開通VIP,暢享免費電子書等14項超值服

開通VIP
Export dialogs in MFC Extension DLLs
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:

 

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.

CString strText;strText.LoadString( ID_MY_TEXT );afxDump << strText;

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.)

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.

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.

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:

    CMyApp::OnDLLDialog()    {    CDLLDialog dlg;    dlg.DoModal();    }    

As you see there is no need for an export function (which would not be very OO).

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.

Here it is:
/////////////////////////////////////////////////////////////////////////////////////////////
// File ExtDllState.h
////////////////////////////////////////////////////////////////////////////////////////////
#ifndef __EXTDLLSTATE_H__
#define __EXTDLLSTATE_H__

class CEXTDLLState
{
public:
  CEXTDLLState();
  ~CEXTDLLState();
protected:
  HINSTANCE m_hInstOld;
};

#endif
////////////////////////////////////////////////////////////////////////////////////////////
File ExtDllState.cpp
////////////////////////////////////////////////////////////////////////////////////////////
CEXTDLLState::CEXTDLLState()
{
  m_hInstOld = AfxGetResourceHandle();
  AfxSetResourceHandle(extensionDLL.hModule);
}

CEXTDLLState::~CEXTDLLState()
{
  AfxSetResourceHandle(m_hInstOld);
}

Quite short as you may see, but there is a little more to do:

Copy the class texts from above into the files ExtDllState.h and ExtDllState.cpp. Put BOTH files in a public include directory where every project can reach it. In your DLL go to the main source file (which is named after the DLL). Here you find something like this:

static AFX_EXTENSION_MODULE MY_DLL_NAMEDLL = { NULL, NULL };    
where MY_DLL_NAME your dll name is (:

 

Replace this variable name with "extensionDLL". Below this line put the following lines:

    #include "EXTDLLState.h"    #include "ExtDllState.cpp"    

Look for occurrences of MY_DLL_NAMEDLL in the rest of the file and replace it with extensionDLL. Occurrences can only happen in this file since the variable is static.

Now if you want to export a Dialog go into the source file of the corresponding class and include EXTDLLState.h again. Override the function DoModal() (Best done with the ClassWizard). You should get something like:

int CMyDLLDlg::DoModal()    {      // TODO: Add your specialized code here and/or call the base class      return CDialog::DoModal();    }    
replace the TODO line with "CEXTDLLState State;". Now it looks like

 

int CDLLDlgDlg::DoModal()    {      CEXTDLLState State;      return CDialog::DoModal();    }    

With this approach you got a comfortable way to export classes that use resources. Be aware that if you need resources in other places too, to define CEXTDLLState before use. (Especially this must be done with modeless dialogs!!!).

You can use CEXTDLLState everywhere you want to access resources in mfc-ext-dlls. You will always get the right thing. I hope this will help some of you, since I had some troubles till I found an easy and nice way to do handle this.

/////////////////////////////////////////////////////////////////////////
本站僅提供存儲服務(wù),所有內(nèi)容均由用戶發(fā)布,如發(fā)現(xiàn)有害或侵權(quán)內(nèi)容,請點擊舉報。
打開APP,閱讀全文并永久保存 查看更多類似文章
猜你喜歡
類似文章
不再繁瑣的'打印機設(shè)置',只要這個VBA代碼!
關(guān)于模式與非模式對話框
Visual C .NET編程講座之五
[轉(zhuǎn)載]VBA調(diào)用Excel自身對話框方法
VS2010/MFC編程入門之十一(對話框:模態(tài)對話框及其彈出過程)
在DLL中產(chǎn)生對話框的方法二(MFC Regular DLL)(轉(zhuǎn))
更多類似文章 >>
生活服務(wù)
分享 收藏 導(dǎo)長圖 關(guān)注 下載文章
綁定賬號成功
后續(xù)可登錄賬號暢享VIP特權(quán)!
如果VIP功能使用有故障,
可點擊這里聯(lián)系客服!

聯(lián)系客服