Question

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.

Was it helpful?

Solution

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.

OTHER TIPS

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

.pro file add: DEFINES += IB_USE_STD_STRING

avoid use MFC CString

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top