| # Gaudi Framework, version v21r7p1 |

Home |  | Generated: 15 Feb 2010

# Win32PsApi.h

Go to the documentation of this file.

    00001 //====================================================================
    00002 //      Win32PsApi.h
    00003 //--------------------------------------------------------------------
    00004 //
    00005 //      Package    : System (The LHCb System service)
    00006 //
    00007 //  Description: Definition of Systems internals for WIN32
    00008 //               This file is NOT meant to be used outside this
    00009 //               sub-package!
    00010 //
    00011 //      Author     : M.Frank
    00012 //  Created    : 13/11/00
    00013 //      Changes    :
    00014 //====================================================================
    00015 #ifndef GAUDI_SYSTEM_WIN32PSAPI_H
    00016 #define GAUDI_SYSTEM_WIN32PSAPI_H
    00017 #ifdef _WIN32
    00018     typedef struct _MODULEINFO {
    00019       LPVOID lpBaseOfDll;
    00020       DWORD SizeOfImage;
    00021       LPVOID EntryPoint;
    00022     } MODULEINFO, *LPMODULEINFO;
    00023     typedef struct _PSAPI_WS_WATCH_INFORMATION {
    00024       LPVOID FaultingPc;
    00025       LPVOID FaultingVa;
    00026     } PSAPI_WS_WATCH_INFORMATION, *PPSAPI_WS_WATCH_INFORMATION;
    00027     typedef struct _PROCESS_MEMORY_COUNTERS {
    00028         DWORD cb;
    00029         DWORD PageFaultCount;
    00030         DWORD PeakWorkingSetSize;
    00031         DWORD WorkingSetSize;
    00032         DWORD QuotaPeakPagedPoolUsage;
    00033         DWORD QuotaPagedPoolUsage;
    00034         DWORD QuotaPeakNonPagedPoolUsage;
    00035         DWORD QuotaNonPagedPoolUsage;
    00036         DWORD PagefileUsage;
    00037         DWORD PeakPagefileUsage;
    00038     } PROCESS_MEMORY_COUNTERS;
    00039     typedef PROCESS_MEMORY_COUNTERS *PPROCESS_MEMORY_COUNTERS;
    00040
    00041   class PsApiFunctions    {
    00042   public:
    00043     bool m_isValid;
    00044     BOOL  (WINAPI *EnumProcesses)           (DWORD* lpidProcess, DWORD   cb, DWORD * cbNeeded);
    00045     BOOL  (WINAPI *EnumProcessModules)      (HANDLE hProcess, HINSTANCE *lphModule, DWORD cb, LPDWORD lpcbNeeded);
    00046     DWORD (WINAPI *GetModuleBaseNameA)      (HANDLE hProcess, HINSTANCE hModule, LPSTR lpBaseName, DWORD nSize );
    00047     DWORD (WINAPI *GetModuleFileNameExA)    (HANDLE hProcess, HINSTANCE hModule, LPSTR lpFilename, DWORD nSize);
    00048     BOOL  (WINAPI *GetModuleInformation)    (HANDLE hProcess, HMODULE hModule, LPMODULEINFO lpmodinfo, DWORD cb );
    00049     BOOL  (WINAPI *EmptyWorkingSet)         (HANDLE hProcess);
    00050     BOOL  (WINAPI *QueryWorkingSet)         (HANDLE hProcess, PVOID pv, DWORD cb );
    00051     BOOL  (WINAPI *InitializeProcessForWsWatch)(HANDLE hProcess);
    00052     BOOL  (WINAPI *GetWsChanges)            (HANDLE hProcess, PPSAPI_WS_WATCH_INFORMATION lpWatchInfo, DWORD cb);
    00053     DWORD (WINAPI *GetMappedFileNameA)      (HANDLE hProcess, LPVOID lpv, LPSTR lpFilename, DWORD nSize );
    00054     BOOL  (WINAPI *EnumDeviceDrivers)       (LPVOID *lpImageBase, DWORD cb, LPDWORD lpcbNeeded );
    00055     DWORD (WINAPI *GetDeviceDriverBaseNameA)(LPVOID ImageBase, LPSTR lpBaseName, DWORD nSize );
    00056     DWORD (WINAPI *GetDeviceDriverFileNameA)(LPVOID ImageBase, LPSTR lpFilename, DWORD nSize );
    00057     BOOL  (WINAPI *GetProcessMemoryInfo)    (HANDLE Process,   PPROCESS_MEMORY_COUNTERS ppsmemCounters, DWORD cb );
    00058     void load(HINSTANCE handle, const char* name, void** pFunction)    {
    00059       *pFunction = (void*)::GetProcAddress(handle, name);
    00060       if ( 0 == *pFunction ) m_isValid = false;
    00061     }
    00062     bool isValid()    const   {
    00063       return m_isValid;
    00064     }
    00065     PsApiFunctions()    {
    00066       m_isValid = true;
    00067       HINSTANCE mh = ::LoadLibrary("PSAPI.DLL");
    00068       if ( 0 == mh )  {
    00069         m_isValid = false;
    00070       }
    00071       else  {
    00072         load( mh, "EnumProcesses",                (void**)&EnumProcesses );
    00073         load( mh, "EnumProcessModules",           (void**)&EnumProcessModules );
    00074         load( mh, "GetModuleBaseNameA",           (void**)&GetModuleBaseNameA );
    00075         load( mh, "GetModuleFileNameExA",         (void**)&GetModuleFileNameExA );
    00076         load( mh, "GetModuleInformation",         (void**)&GetModuleInformation );
    00077         load( mh, "EmptyWorkingSet",              (void**)&EmptyWorkingSet );
    00078         load( mh, "QueryWorkingSet",              (void**)&QueryWorkingSet );
    00079         load( mh, "InitializeProcessForWsWatch",  (void**)&InitializeProcessForWsWatch );
    00080         load( mh, "GetWsChanges",                 (void**)&GetWsChanges );
    00081         load( mh, "GetMappedFileNameA",           (void**)&GetMappedFileNameA );
    00082         load( mh, "EnumDeviceDrivers",            (void**)&EnumDeviceDrivers );
    00083         load( mh, "GetDeviceDriverBaseNameA",     (void**)&GetDeviceDriverBaseNameA );
    00084         load( mh, "GetDeviceDriverFileNameA",     (void**)&GetDeviceDriverFileNameA );
    00085         load( mh, "GetProcessMemoryInfo",         (void**)&GetProcessMemoryInfo );
    00086       }
    00087     }
    00088   };
    00089 #endif
    00090
    00091 #endif    // GAUDI_SYSTEM_WIN32PSAPI_H