Agregar compatibilidad con MFC a un proyecto Qt

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!

Estoy usando VS2010.

The lib in question is the API de Interactive Brokers.

preguntado el 22 de mayo de 12 a las 21:05

Is this an open source and freely available library? If so, got a link? -

Interactive brokers API. It is free, but not open sourced -

Did you try modifying the library's header files so they include atlstr.h en lugar de afxstr.h? These two header files might target the same implementation of CString. -

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 :) -

@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!… ) -

2 Respuestas

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.

Respondido el 07 de junio de 12 a las 10:06

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

.pro file add: DEFINES += IB_USE_STD_STRING

avoid use MFC CString

Respondido 16 Oct 12, 11:10

No es la respuesta que estás buscando? Examinar otras preguntas etiquetadas or haz tu propia pregunta.