Adding MFC support to a Qt project
Asked Answered
U

2

11

I have a Qt project and would like to use an external library that includes "afxstr.h". Problem is that whenever I compile after linking to the lib and including their header, I get an error:

#error afxstr.h can only be used in MFC projects.  Use atlstr.h

Of course, my project is not an MFC project and I can't use atlstr.h instead because it's not my library.

I'm looking for a quick solution!

I'm using VS2010.

The lib in question is the Interactive Brokers API.

Unjaundiced answered 22/5, 2012 at 20:26 Comment(11)
Is this an open source and freely available library? If so, got a link?Antigen
Interactive brokers API. It is free, but not open sourcedUnjaundiced
Did you try modifying the library's header files so they include atlstr.h instead of afxstr.h? These two header files might target the same implementation of CString.Leveroni
Well there is a define to use std::string instead of CString. Still would be fun to know the actual answer to how to add MFC support :)Unjaundiced
@DavidMenard Fun...for who? :) Use that #define, MFC is so yesterday. (Or as they say, "nostalgia isn't what it used to be, and it never was." Microsoft didn't use MFC for its own apps and just foisted it on the world. You might as well ask about integrating with Borland OWL at this point...or while you're at it, the BGI! #8282073 )Antigen
@HostileFork I find general knowledge fun XD It's not like it was MY choice to use MFC... + they have other sources for tools that require MFC to build.Unjaundiced
I'm all for general knowledge...just not banging one's head against the wall so it feels good when you stop. It's an unfortunate MFC CString dependency, & an unfortunate API documentation website based on IFRAME (so you can't link to individual pages, tons of console errors in the browser)...are you sure there isn't a more up-and-coming library for your purposes? :-/ Perhaps even an open source one? This one doesn't seem very futureproof.Antigen
The creators of the library created an unnecessary dependency on MFC. They are the ones who must fix it. Since MFC and Qt are both GUI frameworks, I would expect them to be butting heads constantly making compatibility impossible.Convalescence
I ended up beeing able to compile because their tools come with sources, so everytime they use somethign MFC-related (most of which was CException) I added a #ifndef to stop it from compiling.Unjaundiced
May be I'm little late. :) But your Qt Project is built using what qmake/gcc tool-chain or nmake/cl tool-chain? Because I guess if your Qt Project uses nmake/cl tool-chain, you can add MFC support. Or correct it if I'm wrong..Brinn
have no idea why mess QT with MFC, if there's dependencies I would strongly recommend remove those dependencies to MFC, QT is obviously better designed than MFC.Aylesbury
G
4

The respective setting is Configuration Properties/ General, Use of MFC.

The compiler option implied from that is /D "_AFXDLL" when using MFC in a DLL. As for linker options, curiously the explicit linking of windows import libraries (such as kernel32.lib) get removed.

Visual Studio seems to find the respective libraries automatically. However, the "Use of MFC" option is stored with the project file, so I can't say how it would translates to a custom build script.

The first include must be

#include <afx.h>

and you cannot include windows.h before that. Typically, that's the first include in stdafx.h if you use precompiled headers. Other than that, other MFC headers can be included freely as needed.

I doubt that this is the end of the story, getting MFC to play with anything is painful, and sometimes it's easier to give up :) A quick google reveals that there are solutions, but they involve additional code and are rather old.

Greff answered 7/6, 2012 at 9:50 Comment(0)
F
1

well, you have already know this, just make it more clear:

.pro file add: DEFINES += IB_USE_STD_STRING

avoid use MFC CString

Flieger answered 16/10, 2012 at 10:2 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.