extention dll

1.指從MFC中繼承過來的DLL,一般要求使用共享MFC DLL進行連接,也要求調用者也使用MFC且使用共享MFC,如此可保證DLL與調用者有相同的MFC庫。

2.在使用資源的時候,打個比方說,加載一個對話框,會調用 AfxGetResourceInstance () 進行獲取HINSTANCE,這個函數會自動獲取DLL的 hInstance,所以,這牠不會造成調用者與DLL的資源混淆。

normal dll

1.這個可以當成普通的DLL,調用者可以不是基於MFC編寫,這個DLL可以使用共享或靜態連接。

2.在使用資源的時候,AfxGetResourceInstance () 會得到調用者的 hInstance,所以這個時候,會產生資源加載混淆,經常會出現對話框彈不出來的情況,一般會在需要使用DLL資源的導出函數中加入:AFX_MANAGE_STATE(AfxGetStaticModuleState( )); 這樣,就可以把hInstance轉換成DLL的hInstance,可以正確加載資源了。

完整的區別:

地址:http://www.cnblogs.com/taoxu0903/archive/2009/05/10/1453718.html

1. Dll types
Three:
Win32 dll
MFC regular dll
MFC extension dll
2. MFC extension dll
Basic[MSDN]:
An MFC extension DLL is a DLL that typically implements reusable classes derived from the existing Microsoft Foundation Class Library classes. An MFC extension DLL has the following features and requirements: * The client executable must be an MFC application compiled with _AFXDLL defined.
* An extension DLL can also be used by a regular DLL that is dynamically linked to MFC.
* Extension DLLs should be compiled with _AFXEXT defined. This forces _AFXDLL to be also defined and ensures that the proper declarations is pulled in from the MFC header files. It also ensures that AFX_EXT_CLASS is defined as __declspec(dllexport) while building the DLL, which is necessary if you are using this macro to declare the classes in your extension DLL.
* Extension DLLs should not instantiate a class derived from CWinApp, but should rely on the client application (or DLL) to provide this object. [my note: since every CWinApp needs to manage its module state, as extension dll just use the caller's, so it just accepts the current module state.]
* Extension DLLs should, however, provide a DllMain function and do any necessary initialization there. An MFC extension DLL uses a shared version of MFC in the same way an application uses the shared DLL version of MFC, with a few additional considerations: * It does not have a CWinApp-derived object. It must work with the CWinApp-derived object of the client application. This means that the client application owns the main message pump, the idle loop, and so on.
* It calls AfxInitExtensionModule in its DllMain function. The return value of this function should be checked. If a zero value is returned from AfxInitExtensionModule, return 0 from your DllMain function.
* It creates a CDynLinkLibrary object during initialization if the extension DLL wants to export CRuntimeClass objects or resources to the application. Memory Management MFCx0.dll and all extension DLLs loaded into a client application's address space use the same memory allocator, resource loading, and other MFC global states as if they were in the same application. This is significant because the non-MFC DLL libraries and the regular DLLs do the exact opposite and have each DLL allocating out of its own memory pool. Sharing Resources and Classes Exporting resources is done through a resource list. Each application contains a singly linked list of CDynLinkLibrary objects. When looking for a resource, most of the standard MFC implementations that load resources look first at the current resource module (AfxGetResourceHandle) and if the resource is not found walk the list of CDynLinkLibrary objects attempting to load the requested resource. Walking the list has the disadvantages that it is slightly slower and requires managing resource ID ranges. It has the advantage that a client application that links to several extension DLLs can use any DLL-provided resource without having to specify the DLL instance handle. AfxFindResourceHandle is an API used for walking the resource list to look for a given match. It takes the name and type of a resource and returns the resource handle where it was first found (or NULL). If you do not want to walk the list and only load resources from a specific place, use the functions AfxGetResourceHandle and AfxSetResourceHandle to save the old handle and set the new handle. Be sure to restore the old resource handle before you return to the client application. For an example of using this approach to explicitly load a menu, see Testdll2 .cpp in the MFC sample DLLHUSK. 3. MFC regular dll (Talk only Regular DLLs Dynamically Linked to MFC) Basic [MSDN]: A regular DLL dynamically linked to MFC is a DLL that uses MFC internally, and the exported functions in the DLL can be called by either MFC or non-MFC executables. As the name describes, this kind of DLL is built using the dynamic-link library version of MFC (also known as the shared version of MFC). Functions are usually exported from a regular DLL using the standard C interface.
You must add the AFX_MANAGE_STATE macro at the beginning of all the exported functions in regular DLLs that dynamically link to MFC to set the current module state to the one for the DLL. This is done by adding the following line of code to the beginning of functions exported from the DLL: AFX_MANAGE_STATE(AfxGetStaticModuleState( )) A regular DLL, dynamically linked to MFC has the following features: * This is a new type of DLL introduced by Visual C++ 4.0.
* The client executable can be written in any language that supports the use of DLLs (C, C++, Pascal, Visual Basic, and so on); it does not have to be an MFC application.
* Unlike the statically linked regular DLL, this type of DLL is dynamically linked to the MFC DLL (also known as the shared MFC DLL).
* The MFC import library linked to this type of DLL is the same one used for extension DLLs or applications using the MFC DLL: MFCxx(D).lib. A regular DLL, dynamically linked to MFC has the following requirements: * These DLLs are compiled with _AFXDLL defined, just like an executable that is dynamically linked to the MFC DLL. But _USRDLL is also defined, just like a regular DLL that is statically linked to MFC.
* This type of DLL must instantiate a CWinApp-derived class. * This type of DLL uses the DllMain provided by MFC. Place all DLL-specific initialization code in the InitInstance member function and termination code in ExitInstance as in a normal MFC application. All memory allocations within a regular DLL should stay within the DLL; the DLL should not pass to or receive from the calling executable any of the following:
* pointers to MFC objects
* pointers to memory allocated by MFC If you need to do any of the above, or if you need to pass MFC-derived objects between the calling executable and the DLL, then you must build an extension DLL. Key points:
1) it has its own module state. So regards to resource loading (string, dialog, etc), in order to load its resource correctly, module state switch before loading resource is a must.
2) for every exported function from this dll, the switching module state sentence must be the first code line of every function.
3) The AFX_MANAGE_STATE macro should not be used in regular DLLs that statically link to MFC or in extension DLLs. 4. Loading resource example (from codeguru) The article link is:http://www.codeguru.com/cpp/w-p/dll/article.php/c109 [Key extraction]The next issue involving DLLs and dialog boxes, involves a DLL invoking a dialog which is located in a different DLL. There are four calling possibilities: 1. Regular calling and Regular DLL, 2. An Extension calling and Regular DLL, 3. A Regular calling an Extension DLL, 4. Extension calling a Extension DLL.
case 1: since it's hard to directly use the exported dialog class as module state can't be switched to the parent regular dll's of the wanted dialog, the dialog resource can't be located, the only way to be able to call the dialog is by exporting a function which inside it can show the dialog.
case 2: same as #1.
case 3: as the regular dll has its module state and the extension dll has no way to join in its resource chain and no way to do module state switch as it can only accept the caller's module state, so no way to realize the dialog call here.
case 4: easy. any way can be fine. 5. Other 1) No need to worry about the project setting's preprocessors and CRT setting. New a MFC extension or regular dll in VS, you will get standard setting there. 2) MFC Module state. Only regular dll needs to manage module state, while for MFC extension dll, it will only accept a module state as it may be called by regular dll or MFC application directly (exe), but it really has no way to do sth with module state.

mfc extention dll 與 normal dll 的區別的更多相关文章

  1. 四种DLL:NON-MFC DLL, Regular DLL Statically/Dynamically Linked to MFC, MFC Extension DLL

    参考资料: https://msdn.microsoft.com/en-us/library/30c674tx.aspx http://www.cnblogs.com/qrlozte/p/484442 ...

  2. vc编译器 msvcr.dll、msvcp.dll的含义和相关错误的处理

    转自:http://blog.csdn.net/sptoor/article/details/6203376 很久没有写程式设计入门知识的相关文章了,这篇文章要来谈谈程式库 (Library) 连结, ...

  3. dll的概念 dll导出变量 函数 类

    1. DLL的概念 DLL(Dynamic Linkable Library),动态链接库,可以向程序提供一些函数.变量或类.这些可以直接拿来使用. 静态链接库与动态链接库的区别:   (1)静态链接 ...

  4. 常规DLL与扩展DLL区别

    1.常规DLL可以被各种程序(python,VB等)调用,扩展DLL只能被MFC程序调用.提供给外部使用的控件类只能用扩展DLL. 2.扩展DLL的入口函数是DllMain(),而常规DLL入口是继承 ...

  5. 无法加载 DLL“SQLite.Interop.dll”: 找不到指定的模块。 (异常来自 HRESULT:0x8007007E)

    SQLite部署-无法加载 DLL“SQLite.Interop.dll”: 找不到指定的模块 近期刚使用SQLite,主要引用的是System.Data.SQLite.dll这个dll,在部署到测试 ...

  6. 安装WampServer时出现的问题(丢失VCRUNTIME140.dll或MSVCR110.dll)以及解决办法

    今天,在安装WampServer时,刚开始提示了"丢失VCRUNTIME140.dll"的问题. 我就网上查了一下,结果大家说是没有安装VC++,然后我就按照网友们提供的网址去下载 ...

  7. SQLite部署-无法加载 DLL“SQLite.Interop.dll”: 找不到指定的模块

    近期刚使用SQLite,主要引用的是System.Data.SQLite.dll这个dll,在部署到测试环境时报无法加载 DLL“SQLite.Interop.dll”: 找不到指定的模块. (异常来 ...

  8. C++ 生成 dll 和调用 dll 的方法实例(转)

    1)生成dll 建立两个文件 xxx.h , xxx.cpp xxx.h内容如下: #ifdef BUILD_XXX_DLL#define EXPORT __declspec(dllexport)#e ...

  9. 从新注册 .DLL CMD 运行regsvr32 *.dll注册该DLL 或 regsvr32 /s *.DLL 求证

    从新注册 .DLL  CMD 运行regsvr32  *.dll注册该DLL  或 regsvr32 /s  *.DLL 求证

随机推荐

  1. RequiredFieldValidator的使用

    特別說明:1.一個Button要對頁面的多個控件進行驗證,則需要設置button和其它受控控件的ValidationGroup屬性 aspx頁面實例: <tr class="h&quo ...

  2. jQuery和js如何判断checkbox是否选中

    jquery: <div id="divId" class="divTable"><div class="tableBody&quo ...

  3. 第二百零五天 how can I 坚持

    身体无论什么时候都是最重要的.肝血管瘤,头一次听说,应该没什么大碍.父母年龄大了,我们也该尽快把自己的事情处理好,让他们放心了. 规律作息,合理饮食,多注意锻炼. 该怎么办.不能这拖下去. 好好规划下 ...

  4. Spark RDD概念学习系列之RDD的转换(十)

    RDD的转换 Spark会根据用户提交的计算逻辑中的RDD的转换和动作来生成RDD之间的依赖关系,同时这个计算链也就生成了逻辑上的DAG.接下来以“Word Count”为例,详细描述这个DAG生成的 ...

  5. Python 网页爬虫 & 文本处理 & 科学计算 & 机器学习 & 数据挖掘兵器谱(转)

    原文:http://www.52nlp.cn/python-网页爬虫-文本处理-科学计算-机器学习-数据挖掘 曾经因为NLTK的缘故开始学习Python,之后渐渐成为我工作中的第一辅助脚本语言,虽然开 ...

  6. <转载>内存管理内幕-动态分配的选择、折衷和实现 对malloc内存分配有个简单的描述,对内存管理有个大致的说明

    这篇文章看后感觉不错,和我在glibc下的hurdmalloc.c文件里关于malloc的实现基本意思相同,同时,这篇文章还介绍了一些内存管理方面的知识,值得推荐. 原文链接地址为:http://ww ...

  7. TcxGrid导出EXCEL

    function ExportExcel(grid: TcxGrid; const fileName: string = '1.xls'): Boolean;var  sd: TSaveDialog; ...

  8. VISIO 2007 修改形状默认字体 自定义模具

    visio 2007的形状的默认字体为8号,比较小,怎样改成默认10号? 首先将一个流程图中所要用的形状都拖到绘图区,然后全选,设置字体为10号,全选,再拖动到形状区,如下图: 点击‘是’,确认修改模 ...

  9. Windows 消息机制详解

    总的来说: MSG包括: 窗口句柄,指示MSG发送的目的窗口 消息标识 lPARAM.wParam 发送时间 发送时的鼠标位置   关于消息队列: Windows系统有一个系统消息队列 每个线程都有一 ...

  10. VS2010 用WebBrowser控件 无响应

    问题:偶尔我遇到这个问题,不知怎么的,拖放这个web控件它就卡死,无法响应,其他应用程序没有影响,任务管理器显示无法响应. 解决:原来是有道翻译的问题,具体为什么不清楚,只要一打开有道翻译,用web控 ...