Tuesday, October 27, 2015

'atlbase.h': No such file or directory

Error code:
#include <atlbase.h>

Error:
1    error C1083: Cannot open include file: 'atlbase.h': No such file or directory
2    IntelliSense: cannot open source file "atlbase.h"

This error occurs if you are using atlbase.h file in your program in Visual C++ Express Edition instead of Visual Studio. The reason is express edition does not come with Microsoft Platform SDK as studio does so we need to install it separately and need to modify a couple of lines.

Solution:
1. Download and install Windows Server 2003 SP1 Platform SDK from http://www.microsoft.com/en-us/download/details.aspx?id=6510
2. If you have a 64-bit OS/Processor (Intel i5, Windows 7 64-bit) then install PSDK-amd64.exe as other two won't work.
3. Go to your installation directory to edit atlbase.h file, default would be C:\Program Files\Microsoft Platform SDK\Include\atl
4. Make following changes


change following lines:

PVOID __stdcall __AllocStdCallThunk(VOID);
VOID  __stdcall __FreeStdCallThunk(PVOID);

#define AllocStdCallThunk() __AllocStdCallThunk()
#define FreeStdCallThunk(p) __FreeStdCallThunk(p)

#pragma comment(lib, "atlthunk.lib")

to this:

/*
PVOID __stdcall __AllocStdCallThunk(VOID);
VOID  __stdcall __FreeStdCallThunk(PVOID);

#define AllocStdCallThunk() __AllocStdCallThunk()
#define FreeStdCallThunk(p) __FreeStdCallThunk(p)

#pragma comment(lib, "atlthunk.lib")
*/

#define AllocStdCallThunk() HeapAlloc(GetProcessHeap(),0, sizeof(_stdcallthunk))

#define FreeStdCallThunk(p) HeapFree(GetProcessHeap(), 0, p)

5. Go back to your project and click on properties
6. Click on VC++ directories > Include directories
7. Edit and add the path to atlbase.h file:
C:\Program Files\Microsoft Platform SDK\Include\atl
8. That's it, it should work fine now.

No comments:

Post a Comment

Note: Only a member of this blog may post a comment.