Go4Expert

Go4Expert (http://www.go4expert.com/)
-   C++ (http://www.go4expert.com/forums/cpp/)
-   -   Error in vc++ code (http://www.go4expert.com/forums/error-vcpp-code-t23334/)

rahulonly4u 17Sep2010 15:07

Error in vc++ code
 
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

shabbir 17Sep2010 15:25

Re: Error in vc++ code
 
Is that file present on your PC

rahulonly4u 17Sep2010 15:27

Re: Error in vc++ code
 
Yes when i use go to definition i get the header file

jimblumberg 17Sep2010 18:20

Re: Error in vc++ code
 
Are you linking the library in the project?

xpi0t0s 18Sep2010 13:04

Re: Error in vc++ code
 
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 20Sep2010 11:02

Re: Error in vc++ code
 
Quote:

Originally Posted by xpi0t0s (Post 72908)
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


All times are GMT +5.5. The time now is 22:11.