MFC Applikation die WTL Klassen nutzt
-
Hallo!
Wie kann ich MFC und WTL mischen? Ich bekomme lauter Fehler und der Artikel http://www.codeproject.com/KB/wtl/mix_wtl_mfc.aspx auf CodeProject hat mir leider auch nicht geholfen.
Gruß
HaJo
-
Könntest Du einfach sagen was Dein Problemist und das etwas detailierter.
Den Pauschal gibt der Artikel Dir ja eine Lösung!
-
Also. Wenn ich die Zeilen
// Add support for ATL/WTL #define _WTL_NO_AUTOMATIC_NAMESPACE #include <atlbase.h> #include <atlapp.h> extern WTL::CAppModule _Module;zur stdafx.h hinzufügen erhalte ich folgenden Kompiler-Fehler:
error C2039: 'CString' : is not a member of 'ATL' atlgdi.h 2604.
Wenn ich die Zeilen an den Anfang der stdafx.h einfüge oder aber die vorgeschlagene Lösung dieses Beitrags (Re: Mixing MFC with WTL)
#define _WTL_FORWARD_DECLARE_CSTRING #define _WTL_NO_AUTOMATIC_NAMESPACE #include <atlbase.h> #include <atlapp.h> #include <atlwin.h> #include <atlddx.h> #include <atlctrls.h> #include <atlctrlx.h> #include <atlframe.h> #include <atldlgs.h> #include <atlscrl.h> #include <atlmisc.h>verwende, erhalte ich beide male den Kompiler-Fehler:
Error 2 fatal error C1189: #error : WINDOWS.H already included. MFC apps must not #include <windows.h> afxv_w32.h 16.
Meine stdafx.h sieht wie folgt aus (WTL Includes habe ich mal auskommentiert):
// stdafx.h: Includedatei für Standardsystem-Includedateien // oder häufig verwendete, projektspezifische Includedateien, // die nur selten geändert werden. #pragma once //#define _WTL_FORWARD_DECLARE_CSTRING //#define _WTL_NO_AUTOMATIC_NAMESPACE ////#define _WIN32_WCE_AYGSHELL 1 //#include <atlbase.h> //#include <atlapp.h> //#include <atlwin.h> //#include <atlddx.h> //#include <atlctrls.h> //#include <atlctrlx.h> //#include <atlframe.h> //#include <atldlgs.h> //#include <atlscrl.h> //#include <atlmisc.h> #ifndef _SECURE_ATL #define _SECURE_ATL 1 #endif #ifndef VC_EXTRALEAN #define VC_EXTRALEAN // Selten verwendete Teile der Windows-Header ausschließen #endif #include "targetver.h" #define _ATL_CSTRING_EXPLICIT_CONSTRUCTORS // einige CString-Konstruktoren sind explizit // Deaktiviert das Ausblenden einiger häufiger und oft ignorierter Warnungen durch MFC #define _AFX_ALL_WARNINGS #include <afxwin.h> // MFC-Kern- und -Standardkomponenten #include <afxext.h> // MFC-Erweiterungen #include <afxdisp.h> // MFC-Automatisierungsklassen #ifndef _AFX_NO_OLE_SUPPORT #include <afxdtctl.h> // MFC-Unterstützung für allgemeine Steuerelemente von Internet Explorer 4 #endif #ifndef _AFX_NO_AFXCMN_SUPPORT #include <afxcmn.h> // MFC-Unterstützung für allgemeine Windows-Steuerelemente #endif // _AFX_NO_AFXCMN_SUPPORT #include <afxcontrolbars.h> // MFC-Unterstützung für Multifunktionsleisten und Steuerleisten #ifdef _UNICODE #if defined _M_IX86 #pragma comment(linker,"/manifestdependency:\"type='win32' name='Microsoft.Windows.Common-Controls' version='6.0.0.0' processorArchitecture='x86' publicKeyToken='6595b64144ccf1df' language='*'\"") #elif defined _M_IA64 #pragma comment(linker,"/manifestdependency:\"type='win32' name='Microsoft.Windows.Common-Controls' version='6.0.0.0' processorArchitecture='ia64' publicKeyToken='6595b64144ccf1df' language='*'\"") #elif defined _M_X64 #pragma comment(linker,"/manifestdependency:\"type='win32' name='Microsoft.Windows.Common-Controls' version='6.0.0.0' processorArchitecture='amd64' publicKeyToken='6595b64144ccf1df' language='*'\"") #else #pragma comment(linker,"/manifestdependency:\"type='win32' name='Microsoft.Windows.Common-Controls' version='6.0.0.0' processorArchitecture='*' publicKeyToken='6595b64144ccf1df' language='*'\"") #endif #endif //// Add support for ATL/WTL //#define _WTL_FORWARD_DECLARE_CSTRING //#define _WTL_NO_AUTOMATIC_NAMESPACE //#include <atlbase.h> // //#include <atlapp.h> // // //extern WTL::CAppModule _Module;Wie kann ich das Problem denn lösen?
-
Füge die ATL Dateien erst nach den MFC Includes ein!
-
Martin Richter schrieb:
Füge die ATL Dateien erst nach den MFC Includes ein!
Dann erhalte ich doch den Kompiler Fehler
Error 1 error C2039: 'CString' : is not a member of 'ATL' atlgdi.h 2604Könntest Du mir ein Beispiel einer stdafx.h zeigen?
-
// stdafx.h : include file for standard system include files, // or project specific include files that are used frequently, // but are changed infrequently #pragma once #ifndef RC_INVOKED ///////////////////////////////////////////////////////////////////////////// // Platform selection // Use the standard defines #include "PlatformDefinition.h" // Don't use the public MFC manifest's #define _PRIVATE_CRT_MANIFEST_ // create CRT manifests #define _PRIVATE_MFC_MANIFEST_ // create MFC manifests #define _PRIVATE_MFCLOC_MANIFEST_ // create MFC manifests for the locale files. #include "UsePrivateMSCAssemblies.h" ///////////////////////////////////////////////////////////////////////////// // CRT & other defines Defines #ifndef VC_EXTRALEAN #define VC_EXTRALEAN // Exclude rarely-used stuff from Windows headers #endif #define _CRT_SECURE_NO_WARNINGS ///////////////////////////////////////////////////////////////////////////// // Standard includes from MCF and ATL #define _ATL_ATTRIBUTES #define _ATL_APARTMENT_THREADED #define _ATL_CSTRING_EXPLICIT_CONSTRUCTORS // some CString constructors will be explicit // turns off MFC's hiding of some common and often safely ignored warning messages #define _AFX_ALL_WARNINGS /* The sequence will guaranty that GetAsDBTIMESTAMP ist compiled. * if oledb.h ist included later GetAsDBTIMESTAMP ist not included in the * basic classes */ #include <afx.h> // MFC core and standard components #include <oledb.h> #include <afxwin.h> // MFC core and standard components #include <afxext.h> // MFC extensions #include <afxdisp.h> // MFC Automation classes #include <afxmt.h> // MFC multithreading #include <afxtempl.h> // MFC templates #include <afxdtctl.h> // MFC support for Internet Explorer 4 Common Controls #ifndef _AFX_NO_AFXCMN_SUPPORT #include <afxcmn.h> // MFC support for Windows Common Controls #endif // _AFX_NO_AFXCMN_SUPPORT #define _ATL_ATTRIBUTES #include <atlbase.h> #include <atldbcli.h> #include <atlcom.h> ///////////////////////////////////////////////////////////////////////////// // STL // Omiting warning C4702 "Unreachable code" in the STL #pragma warning(push) #pragma warning(disable: 4702) #include <vector> #include <list> #include <map> #include <set> #pragma warning(pop) ...
-
Hmm, das lässt sich zwar kompilieren jedoch nicht mehr wenn ich andere WTL-Header hinzufüge wie
#include <atlapp.h> // oder ähnlicheDiese werden aber doch benötigt für globale WTL::CAppModule Klasse. Fehler ist übrigens wieder
Error 1 error C2039: 'CString' : is not a member of 'ATL' atlgdi.h