How to include ATL in VS2012 project

m trying to work with some library code given to me that requires some of the ATL functionality but I consistently get errors like the following:

1>c:\program files (x86)\microsoft visual studio 11.0\vc\atlmfc\include\atltransactionmanager.h(396): error C2039: 'CreateFile' : is not a member of '`global namespace''
1>c:\program files (x86)\microsoft visual studio 11.0\vc\atlmfc\include\atltransactionmanager.h(427): error C2039: 'DeleteFile' : is not a member of '`global namespace''
1>c:\program files (x86)\microsoft visual studio 11.0\vc\atlmfc\include\atltransactionmanager.h(460): error C2039: 'MoveFile' : is not a member of '`global namespace''
1>c:\program files (x86)\microsoft visual studio 11.0\vc\atlmfc\include\atlbase.h(6517): error C2039: 'GetModuleFileName' : is not a member of '`global namespace''
1>c:\program files (x86)\microsoft visual studio 11.0\vc\atlmfc\include\atlbase.h(6517): error C3861: 'GetModuleFileName': identifier not found
1>c:\program files (x86)\microsoft visual studio 11.0\vc\atlmfc\include\atlbase.h(6591): error C2039: 'GetModuleFileName' : is not a member of '`global namespace''
1>c:\program files (x86)\microsoft visual studio 11.0\vc\atlmfc\include\atlbase.h(6591): error C3861: 'GetModuleFileName': identifier not found
1>c:\program files (x86)\microsoft visual studio 11.0\vc\atlmfc\include\statreg.h(481): error C3861: 'FindResource': identifier not found
1>c:\program files (x86)\microsoft visual studio 11.0\vc\atlmfc\include\statreg.h(674): error C3861: 'CreateFile': identifier not found
1>c:\program files (x86)\microsoft visual studio 11.0\vc\atlmfc\include\atlbase.h(6676): error C3861: 'GetModuleFileName': identifier not found
1>c:\program files (x86)\microsoft visual studio 11.0\vc\atlmfc\include\atlbase.h(6762): error C3861: 'GetModuleFileName': identifier not found
1>c:\program files (x86)\microsoft visual studio 11.0\vc\atlmfc\include\atlbase.h(6885): error C3861: 'GetModuleFileName': identifier not found
1>c:\program files (x86)\microsoft visual studio 11.0\vc\atlmfc\include\atlbase.h(7228): error C3861: 'GetModuleFileName': identifier not found
1>c:\program files (x86)\microsoft sdks\speech\v11.0\include\sphelper.h(1246): error C2039: 'LoadLibrary' : is not a member of '`global namespace''
1>c:\program files (x86)\microsoft sdks\speech\v11.0\include\sphelper.h(1246): error C3861: 'LoadLibrary': identifier not found

I do have it installed on my own machine and the original project itself compiles without problem. For confidentiality reasons I can’t share the original project itself, but I can share its compile flags (apologies for poor formatting):

/Yc"stdafx.h" /GS /analyze- /W3 /wd"4995" /Zc:wchar_t /ZI /Gm /Od /Fd"Debug\vc110.pdb" /fp:precise /D "WIN32" /D "_DEBUG" /D "_WINDOWS" /D "_USRDLL" /D "DLL_EXPORTS" /D "_WINDLL" /D "_UNICODE" /D "UNICODE" /errorReport:prompt /WX- /Zc:forScope /RTC1 /Gd /Oy- /MDd /Fa"Debug\" /EHsc /nologo /Fo"Debug\" /Fp"Debug\KinectCommonBridge.pch" 

Here are mine (feel free to ignore the openFrameworks related includes, I’m trying to keep the project as close to their settings as possible so that it translates more easily for users):

/Yc"stdafx.h" /GS /TP /analyze- /W3 /Zc:wchar_t /I"..\..\..\libs\openFrameworks" /I"..\..\..\libs\openFrameworks\graphics" /I"..\..\..\libs\openFrameworks\app" /I"..\..\..\libs\openFrameworks\sound" /I"..\..\..\libs\openFrameworks\utils" /I"..\..\..\libs\openFrameworks\communication" /I"..\..\..\libs\openFrameworks\video" /I"..\..\..\libs\openFrameworks\types" /I"..\..\..\libs\openFrameworks\math" /I"..\..\..\libs\openFrameworks\3d" /I"..\..\..\libs\openFrameworks\gl" /I"..\..\..\libs\openFrameworks\events" /I"..\..\..\libs\glut\include" /I"..\..\..\libs\rtAudio\include" /I"..\..\..\libs\quicktime\include" /I"..\..\..\libs\freetype\include" /I"..\..\..\libs\freetype\include\freetype2" /I"..\..\..\libs\freeImage\include" /I"..\..\..\libs\fmodex\include" /I"..\..\..\libs\videoInput\include" /I"..\..\..\libs\glew\include\" /I"..\..\..\libs\glu\include" /I"..\..\..\libs\tess2\include" /I"..\..\..\libs\cairo\include\cairo" /I"..\..\..\libs\poco\include" /I"..\..\..\libs\glfw\include" /I"..\..\..\libs\openssl\include" /I"..\..\..\addons" /I"src" /I"..\..\..\addons\ofxKinectCommonBridge\src" /I"..\..\..\addons\ofxKinectCommonBridge\libs\KinectCommonBridge\include" /I"..\..\..\addons\ofxGui\src" /I"C:\Program Files (x86)\Microsoft Visual Studio 11.0\VC\atlmfc\include" /ZI /Gm /Od /Fd"obj\Debug\vc110.pdb" /fp:precise /D "WIN32" /D "_DEBUG" /D "_CONSOLE" /D "POCO_STATIC" /D "CAIRO_WIN32_STATIC_BUILD" /D "DISABLE_SOME_FLOATING_POINT" /D "_UNICODE" /D "UNICODE" /errorReport:prompt /WX- /Zc:forScope /RTC1 /Gd /Oy- /MDd /Fa"obj\Debug\" /EHsc /nologo /Fo"obj\Debug\" /Fp"obj\Debug\SpeechExample_debug.pch" 

I’m not very familiar with the ATL or it’s use but this seems to me that it shouldn’t be that difficult to include this file properly. I’ve dug through both projects and I can’t find anything fundamentally different in any of the includes or compiler flags. Thanks for any guidance and I’m happy to provide any more information if it’s helpful.

Have you tried building the project without openFrameworks ? (I’m not sure by your post if your issue is generic to VS2012 or specific of oF+VS2012)

I remember having issues with those type of functions (not ATL specifically, but Kernel32 functions in general) that were not found. My dirty fix was to replace CreateFile by CreateFileA (or CreateFileW) that would solve the issue. So your problem might be a Unicode/Ansi conflict (potentially caused by oF headers).

A good test could be to remove the problematic library, add the proper include and try to call CreateFile, and CreateFileA in a dummy test file, and see if everything compile or not…

I got it figured out, bizarrely I had to include my ATL based project before “ofMain.h”. As soon as I get the project all sorted I’ll post a link to it.

Glad you managed to find a solution for your problem!
I’ve been trying to troubleshoot this problem for a long time. I always find a work around like changing the order of the includes, but I really wonder what in openframeworks code base messes up with the definition of those function.

I had a similar problem and found that in the OpenFrameWorks external dependencies there is a include

//
// UnWindows.h
//
// $Id: //poco/1.4/Foundation/include/Poco/UnWindows.h#1 $
//
// Library: Foundation
// Package: Core
// Module:  UnWindows
//
// A wrapper around the <windows.h> header file that #undef's some
// of the macros for function names defined by <windows.h> that
// are a frequent source of conflicts (e.g., GetUserName).
// 

You can prevent this happening by putting

// prevent POCO includes undefining windows functions
#define POCO_NO_UNWINDOWS 1

before including any OpenFrameWorks includes

1 Like