Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Adding MFC support to a Qt project

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.

like image 341
David Menard Avatar asked May 22 '12 20:05

David Menard


2 Answers

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.

like image 125
peterchen Avatar answered Nov 18 '22 11:11

peterchen


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

.pro file add: DEFINES += IB_USE_STD_STRING

avoid use MFC CString

like image 43
raidsan Avatar answered Nov 18 '22 09:11

raidsan