tags:

views:

267

answers:

5

Hi,

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 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.

A: 

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

Toad
+1  A: 

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.

Martin Beckett
A: 

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.

fupsduck
A: 

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.

Sheng Jiang 蒋晟
A: 

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.