1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Error in vc++ code

Discussion in 'C++' started by rahulonly4u, Sep 17, 2010.

  1. rahulonly4u

    rahulonly4u New Member

    Joined:
    Sep 6, 2010
    Messages:
    29
    Likes Received:
    0
    Trophy Points:
    0
    Occupation:
    software developer
    Location:
    india
    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
     
  2. shabbir

    shabbir Administrator Staff Member

    Joined:
    Jul 12, 2004
    Messages:
    15,287
    Likes Received:
    364
    Trophy Points:
    83
    Is that file present on your PC
     
  3. rahulonly4u

    rahulonly4u New Member

    Joined:
    Sep 6, 2010
    Messages:
    29
    Likes Received:
    0
    Trophy Points:
    0
    Occupation:
    software developer
    Location:
    india
    Yes when i use go to definition i get the header file
     
  4. jimblumberg

    jimblumberg New Member

    Joined:
    May 30, 2010
    Messages:
    120
    Likes Received:
    29
    Trophy Points:
    0
    Are you linking the library in the project?
     
  5. xpi0t0s

    xpi0t0s Mentor

    Joined:
    Aug 6, 2004
    Messages:
    3,012
    Likes Received:
    203
    Trophy Points:
    0
    Occupation:
    Senior Support Engineer
    Location:
    England
    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 likes this.
  6. rahulonly4u

    rahulonly4u New Member

    Joined:
    Sep 6, 2010
    Messages:
    29
    Likes Received:
    0
    Trophy Points:
    0
    Occupation:
    software developer
    Location:
    india
    Thanks problem is solved
     

Share This Page