Reputation: 7400
I have a win32 DLL that includes Windows.h
and makes use of the windows API. I want to load this DLL into an application that uses MFC.
Will this cause any memory leaks or strange behavior? or is it safe?
Upvotes: 0
Views: 690
Reputation: 51395
MFC is implemented on top of the Windows API. An MFC application can call into the Windows API without any restrictions. It is, however, not possible (nor required) to #include <windows.h>
prior to including afxwin.h
. If you do, afxv_w32.h
will error out with the following message:
WINDOWS.H already included. MFC apps must not
#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. Those symbols must be defined prior to including windows.h
(which afxv_w32.h
eventually does include).
Likewise, there are no problems associated with linking against a .dll that is implemented using the Windows API. In fact, a default MFC application already links against a number of Windows API libraries, like kernel32.dll
and user32.dll
. If the header file declaring the .dll exports includes windows.h
you need to make sure that it is included after afxwin.h
. Otherwise the preprocessor will error out with the message quoted above.
Upvotes: 3