简体   繁体   English

在mfc应用程序中使用Win32 dll是否安全?

[英]Is it safe to use a win32 dll in an mfc application?

I have a win32 DLL that includes Windows.h and makes use of the windows API. 我有一个包含Windows.h并使用Windows API的Win32 DLL。 I want to load this DLL into an application that uses MFC. 我想将此DLL加载到使用MFC的应用程序中。

Will this cause any memory leaks or strange behavior? 这会导致任何内存泄漏或奇怪的行为吗? or is it safe? 还是安全?

MFC is implemented on top of the Windows API. MFC是在Windows API之上实现的。 An MFC application can call into the Windows API without any restrictions. MFC应用程序可以无限制地调用Windows API。 It is, however, not possible (nor required) to #include <windows.h> prior to including afxwin.h . 但是,在包含afxwin.h之前,不可能(也不需要) #include <windows.h> If you do, afxv_w32.h will error out with the following message: 如果这样做, afxv_w32.h将出现以下错误消息:

WINDOWS.H already included. WINDOWS.H已包含。 MFC apps must not #include <windows.h> MFC应用程序不得#include <windows.h>

The reason behind this is not a compatibility issue. 其背后的原因不是兼容性问题。 It is due to the fact, that MFC has to set up several preprocessor symbols to control certain aspects of the compilation process. 正是由于这一事实,MFC必须设置几个预处理器符号来控制编译过程的某些方面。 Those symbols must be defined prior to including windows.h (which afxv_w32.h eventually does include). 这些符号必须在包含windows.hafxv_w32.h最终包含)之前定义。

Likewise, there are no problems associated with linking against a .dll that is implemented using the Windows API. 同样,与使用Windows API实现的.dll链接也没有任何问题。 In fact, a default MFC application already links against a number of Windows API libraries, like kernel32.dll and user32.dll . 实际上,默认的MFC应用程序已经链接到许多Windows API库,例如kernel32.dlluser32.dll If the header file declaring the .dll exports includes windows.h you need to make sure that it is included after afxwin.h . 如果声明.dll导出的头文件包含windows.h ,则需要确保afxwin.h之后包含afxwin.h Otherwise the preprocessor will error out with the message quoted above. 否则,预处理器将出错,并显示上面引用的消息。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 在旧的MFC / Win32 DLL中实现CLR并将DLL托管到MFC / Win32应用程序中 - Implementing the CLR into old MFC/Win32 DLL and hosting DLL into MFC/Win32 Application How to export a function of a regular MFC DLL that is statically linked to MFC to use with a non MFC Win32 Console App in C++ - How to export a function of a regular MFC DLL that is statically linked to MFC to use with a non MFC Win32 Console App in C++ 在Win32应用程序中捕获DLL依赖项 - Catching DLL dependencies in Win32 application 从Win32控制台应用程序驱动MFC应用程序 - Drive MFC Application from Win32 Console Application 从Win32 / MFC应用程序中启用后无法使用JNI - Unable to use JNI when enabled from within Win32/MFC application C ++,MFC,选项卡式文档界面应用程序,Win32 - C++, MFC, tabbed document interface application, Win32 如何在Win32 / MFC应用程序中隐藏/折叠主菜单 - How to hide/collapse main menu in a win32/mfc application 如何在C ++ Win32应用程序中使用非托管DLL? - How do I use unmanaged DLL in C++ win32 application? JNI C++ DLL -“UnsatisfiedLinkError: %1 不是有效的 Win32 应用程序” - JNI C++ DLL - 'UnsatisfiedLinkError: %1 is not a valid Win32 application' 无法创建 DLL:获取 DLL“不是有效的 Win32 应用程序” - Unable to create DLLs: Getting DLL "is not a valid Win32 application"
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM