VC生成支持MFC动态库

菠萝猫咪 2015-03-04 02:31:21
我想创建一个支持MFC的动态库程序,导出一个类,要怎么操作呢?
...全文
102 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
赵4老师 2015-03-04
  • 打赏
  • 举报
回复
mk:@MSITStore:H:\MSDN98\98VS\2052\vccore.chm::/html/_core_regular_dlls_dynamically_linked_to_mfc.htm Regular DLLs Dynamically Linked to MFC Home | Overview | How Do I | FAQ | Details | Sample 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. 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, etc.); 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 which is dynamically linked to the MFC DLL. But _USRDLL is also defined, just like a regular DLL which 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. Because this kind of DLL uses the dynamic link library version of MFC, you must explicitly set the current module state to the one for the DLL. To do this, use the AFX_MANAGE_STATE macro at the beginning of every function exported from the DLL. Regular DLLs must have a CWinApp-derived class and a single object of that application class, as does an MFC application. However, the CWinApp object of the DLL does not have a main message pump, as does the CWinApp object of an application. The following MFC capabilities are not applicable in DLLs, either because of technical limitations or because those services are usually provided by the application. CWinApp::Enable3dControls CWinApp::SetDialogBkColor (color is ignored for message boxes) Note that the CWinApp::Run mechanism does not apply to a DLL, since the application owns the main message pump. If your DLL brings up modeless dialogs or has a main frame window of its own, your application's main message pump must call a DLL-exported routine that calls CWinApp::PreTranslateMessage. Place all DLL-specific initialization in the CWinApp::InitInstance member function as in a normal MFC application. The CWinApp::ExitInstance member function of your CWinApp derived class will be called from the MFC provided DllMain function before the DLL is unloaded. You must distribute the shared DLLs MFCx0.DLL and MSVCRT.DLL (or similar files) with your application. See the topic Redistributable Files for a complete list of the MFC redistributable files. A DLL that is dynamically linked to MFC cannot also statically link to MFC. Applications link to regular DLLs dynamically linked to MFC it just like any other DLL. Symbols are usually exported from a regular DLL using the standard C interface. The declaration of a function exported from a regular DLL looks something like this: extern "C" __declspec(dllexport) MyExportedFunction( ); 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. It is safe to pass pointers to memory that were allocated by the C run-time libraries between an application and a DLL only if you make a copy of the data. You must not delete or resize these pointers or use them without making a copy of the memory. When building a regular DLL that dynamically links to MFC, you need to use the macro AFX_MANAGE_STATE to switch the MFC module state correctly. This is done by adding the following line of code to the beginning of functions exported from the DLL: AFX_MANAGE_STATE(AfxGetStaticModuleState( )) The AFX_MANAGE_STATE macro should not be used in regular DLLs that statically link to MFC or in extension DLLs. For more information, see Managing the State Data of MFC Modules. What do you want to do? Initialize regular DLLs What do you want to know more about? The module states of a regular DLL dynamically linked to MFC Managing the state data of MFC modules Using extension DLL,Database/OLE/Sockets in regular DLL Using MFC as Part of a DLL The different kinds of DLLs available with Visual C++
赵4老师 2015-03-04
  • 打赏
  • 举报
回复
MSDN98_1.ISO http://pan.baidu.com/s/1dDF41ix, MSDN98_2.ISO http://pan.baidu.com/s/1bnGo0Vl 先下载安装MSDN98,然后参考: mk:@MSITStore:D:\MSDN98\98VS\2052\vccore.chm::/html/_core_regular_dlls_dynamically_linked_to_mfc.3a_.overview.htm Regular DLLs Dynamically Linked to MFC: Overview Home | Overview | How Do I | FAQ | Details | Sample 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. For an example of how to write, build, and use a regular DLL, see the sample DLLTRACE. For more information about regular DLLs that dynamically link to MFC, see the section titled “Converting DLLTRACE to Dynamically Link with the MFC DLL” in the abstract for the sample. 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( )) For detailed information on converting a regular DLL that statically links to MFC to a DLL that dynamically links to MFC, see the section titled “Converting DLLTRACE to Dynamically Link with the MFC DLL” in the abstract for the DLLTRACE sample. What do you want to do? Initialize a regular DLL What do you want to know more about? Regular DLLs dynamically linked to MFC Non-MFC DLLs: Overview Regular DLLs statically linked to MFC: Overview Extension DLLs: Overview Which kind of DLL to use Using extension DLL, Database/OLE/Sockets in regular DLL The build settings generated by AppWizard for MFC DLLs Managing the state data of MFC modules

64,662

社区成员

发帖
与我相关
我的任务
社区描述
C++ 语言相关问题讨论,技术干货分享,前沿动态等
c++ 技术论坛(原bbs)
社区管理员
  • C++ 语言社区
  • encoderlee
  • paschen
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
  1. 请不要发布与C++技术无关的贴子
  2. 请不要发布与技术无关的招聘、广告的帖子
  3. 请尽可能的描述清楚你的问题,如果涉及到代码请尽可能的格式化一下

试试用AI创作助手写篇文章吧