开发者

How to add MFC support to existing Win32 C++ Project?

开发者 https://www.devze.com 2022-12-15 11:53 出处:网络
I am creating a C++ application which uses Qt to create the GUI. However, I need to use a third party library which relies on MFC (for CString\'s, etc). Is there anyway to add开发者_JAVA百科 MFC to my

I am creating a C++ application which uses Qt to create the GUI. However, I need to use a third party library which relies on MFC (for CString's, etc). Is there anyway to add开发者_JAVA百科 MFC to my application to allow me to use this library or do I need to rewrite it myself?

I saw this question, but it doesn't tell me how to add MFC manually to the project.


If the library app takes/returns/uses CStrings it will need linking with the MFC libs, or will have the MFC libs already statically linked.

If you are using Visual studio you can just check "use MFc in static/shared lib" as appropriate, it doesn;t affect your application GUI as long as you keep your current program entry point.


If it's only for the CString (and perhaps some other utility functions) you might be better of searching for replacements. There are quite a few floating around on the internet.

For example this CString implementation


It would be much easier if you can find a replacement of the third-party MFC library.

The third party library, static or dynamically linked, would require an MFC version that is exactly the same version as the one used to compile the third party lib file. MFC classes are not binary-compatible between versions and not even binary-compatible between configurations (static/dynamically linked MFC & CRT, single/multiple threaded CRT, debug, release, X86, X64, MBCS, UNICODE, etc) of the same version.

If you use CString::LoadString or anything else that access the MFC module state it would require a global CWinApp. An easy way to get it is to create a regular DLL. Adding one to your QT project would require you to move code from your exiting entry function to InitInstance and ExitInstance.


Yes you can use MFC by selecting it in your compile and link options. If your only reason is because of the third party library then you will probably want to refrain from using any MFC features in your own code. That way if you ever replace the third party library you can turn off MFC as well.


If the existing Windows program uses a message loop (instead of the separate event handlers used by MFC) you can subclass a window at whatever level you need to process that message loop and override the WindowProc function.

For example, I took an existing Win32 program and embedded it's main window into a CStatic picture window by substituting the WindowProc of the subclassed CStatic. The functionality of the previous program was contained within the CStatic, but I could add other MFC controls and paradigms into the surrounding border.


To add MFC support to Integra the following changes are needed :

  1. Change app entry point :
    • Normally qt application entry point is main, for MFC application the expected entry point is WinMain/wWinMain.
  2. Add the required MFC dependencies (mfc140d.dll/mfc140.dll, etc).
    • Add System32 folder to environment path to find the necessary dependencies.
    • Package the required dlls while creating the installer
0

精彩评论

暂无评论...
验证码 换一张
取 消