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

Database login error in Visual Studio

Error:
Cannot open user default database. Login failed.
Login failed for user 'abcxyz'.

I got this error in my Visual Web Developer 2010 Express.

My database named Database1.mdf was not opening and throwing this error.

Wednesday, October 21, 2015

Memory usage per process in C++

Code:

#include <windows.h>
#include <stdio.h>
#include <psapi.h>

void PrintMemoryInfo( DWORD processID )
{
    HANDLE hProcess;
    PROCESS_MEMORY_COUNTERS pmc;
    printf( "\nProcess ID: %u\n", processID );
    hProcess = OpenProcess(  PROCESS_QUERY_INFORMATION |
        PROCESS_VM_READ,
        FALSE, processID );
    if (NULL == hProcess)
        return;

Tuesday, October 20, 2015

Name must be a namespace name error in Visual C++

Following error was observed in Microsoft Visual C++ 2010 edition while using std namespace.

Error: IntelliSense: name must be a namespace name

Problem code:

using namespace std;

Solution:

#include <iostream>
using namespace std;

PCH Warning in Visual C++

The following error was observed in Microsoft Visual C++ 2010 edition.

Error:
Error: PCH Warning: header stop cannot be in a macro or #if block. An intellisense PCH file was not generated.

Problem code:

[file name : perCoreUsage.h] 

#ifndef perCoreUsage
#define perCoreUsage

void perCoreUsageCall();

#endif

Solution-1

Add the following line in your header file perCoreUsage.h:
#pragma once

Solution-2

Use your header file in some CPP file like perCoreUsage.cpp or main.cpp:
#include "perCoreUsage.h"