Error in vc++ code

rahulonly4u's Avatar, Join Date: Sep 2010
Go4Expert Member
Code: VC++
#include "stdafx.h"
#include "CalcProcMem.h"
#include <psapi.h>

#ifdef _DEBUG
#define new DEBUG_NEW
#endif



// The one and only application object

CWinApp theApp;

using namespace std;



void PrintMemoryInfo()
{
    HANDLE hProcess;
    PROCESS_MEMORY_COUNTERS pmc;

    // Print the process identifier.

    printf( "\nProcess ID: %u\n", GetCurrentProcessId());

    // Print information about the memory usage of the process.

    hProcess = OpenProcess(  PROCESS_QUERY_INFORMATION |
                                    PROCESS_VM_READ,
                                    FALSE, (DWORD)GetCurrentProcess() );
    if (NULL == hProcess)
        return;

    if ( GetProcessMemoryInfo( GetCurrentProcess(), &pmc, (DWORD)sizeof(pmc)) )
    {
        printf( "\tPageFaultCount: 0x%08X\n", pmc.PageFaultCount );
        printf( "\tPeakWorkingSetSize: 0x%08X\n",
                  pmc.PeakWorkingSetSize );
hi am using this code and i have included #include <psapi.h>
even i am getting error


Error 1 error LNK2019: unresolved external symbol _GetProcessMemoryInfo@12 referenced in function "void __cdecl PrintMemoryInfo(void)" (?PrintMemoryInfo@@YAXXZ) CalcProcMem.obj

Regarads

Rahul
0
shabbir's Avatar, Join Date: Jul 2004
Go4Expert Founder
Is that file present on your PC
0
rahulonly4u's Avatar, Join Date: Sep 2010
Go4Expert Member
Yes when i use go to definition i get the header file
0
jimblumberg's Avatar
Ambitious contributor
Are you linking the library in the project?
0
xpi0t0s's Avatar, Join Date: Aug 2004
Mentor
You need to link the library in. This error is not a compile error, so the compiler has found the header file and all the information it needs. The error is a linker error; it means it can't find the code for PrintMemoryInfo, which is in psapi.lib. Add that file to the project and this should resolve the error. You may also need to add the path to that library to the project.
rahulonly4u like this
0
rahulonly4u's Avatar, Join Date: Sep 2010
Go4Expert Member
Quote:
Originally Posted by xpi0t0s View Post
You need to link the library in. This error is not a compile error, so the compiler has found the header file and all the information it needs. The error is a linker error; it means it can't find the code for PrintMemoryInfo, which is in psapi.lib. Add that file to the project and this should resolve the error. You may also need to add the path to that library to the project.
Thanks problem is solved