Code: #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
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.