PowerBASIC Forums
  Source Code
  PSAPI Header

Post New Topic  Post A Reply
profile | register | preferences | faq | search

UBBFriend: Email This Page to Someone! next newest topic | next oldest topic
Author Topic:   PSAPI Header
JOSE ROCA
Member
posted November 14, 2002 09:27 PM     Click Here to See the Profile for JOSE ROCA     Edit/Delete Message   Reply w/Quote

TYPE ENUM_PAGE_FILE_INFORMATION
cb AS DWORD '// Size of this structure, in bytes.
Reserved AS DWORD '// This member is reserved.
TotalSize AS DWORD '// Total size of the pagefile, in bytes.
TotalInUse AS DWORD '// Current pagefile usage, in bytes.
PeakUsage AS DWORD '// Peak pagefile usage, in bytes.
END TYPE

TYPE MODULEINFO
lpBaseOfDll AS DWORD '// Load address of the module.
SizeOfImage AS DWORD '// Size of the linear space that the module occupies, in bytes.
EntryPoint AS DWORD '// Entry point of the module.
END TYPE

TYPE PERFORMANCE_INFORMATION
cb AS DWORD '// Size of this structure, in bytes.
CommitTotal AS DWORD '// Total number of pages committed by the system.
CommitLimit AS DWORD '// Current maximum number of page commits that
'// can be performed by the system. This number
'// can change if memory is added or deleted, or
'// if pagefiles have grown, shrunk, or been added.
CommitPeak AS DWORD '// Maximum number of page commit totals that have
'// occurred since the last reboot.
PhysicalTotal AS DWORD '// Total amount of physical memory, in pages.
PhysicalAvailable AS DWORD '// Amount of physical memory available to user processes, in pages.
SystemCache AS DWORD '// Total amount of system cache memory, in pages.
KernelTotal AS DWORD '// Total amount of the sum of the paged and nonpaged kernel pools, in pages.
KernelPaged AS DWORD '// Total amount of the paged kernel pool, in pages.
KernelNonpaged AS DWORD '// Total amount of the nonpaged kernel pool, in pages.
PageSize AS DWORD '// Size of a page, in bytes.
HandleCount AS DWORD '// Total number of open handles.
ProcessCount AS DWORD '// Total number of processes.
nThreadCount AS DWORD '// Total number of threads.
END TYPE


TYPE PROCESS_MEMORY_COUNTERS
cb AS DWORD '// Size of the structure, in bytes.
PageFaultCount AS DWORD '// Number of page faults.
PeakWorkingSetSize AS DWORD '// Peak working set size.
WorkingSetSize AS DWORD '// Current working set size.
QuotaPeakPagedPoolUsage AS DWORD '// Peak paged pool usage.
QuotaPagedPoolUsage AS DWORD '// Current paged pool usage.
QuotaPeakNonPagedPoolUsage AS DWORD '// Peak nonpaged pool usage.
QuotaNonPagedPoolUsage AS DWORD '// Current nonpaged pool usage.
PagefileUsage AS DWORD '// Current space allocated for the pagefile.
'// Those pages may or may not be in memory.
PeakPagefileUsage AS DWORD '// Peak space allocated for the pagefile.
END TYPE


TYPE PSAPI_WS_WATCH_INFORMATION
FaultingPc AS DWORD '// Pointer to the instruction that caused the page fault.
FaultingVa AS DWORD '// Pointer to the page that was added to the working set.
END TYPE


DECLARE FUNCTION EmptyWorkingSet LIB "PSAPI.DLL" ALIAS "EmptyWorkingSet" ( _
BYVAL hProcess AS DWORD _
) AS LONG


DECLARE FUNCTION EnumDeviceDrivers LIB "PSAPI.DLL" ALIAS "EnumDeviceDrivers" ( _
lpImageBase AS DWORD, _
BYVAL cb AS DWORD, _
lpcbNeedes AS DWORD _
) AS LONG


DECLARE FUNCTION EnumPageFiles LIB "PSAPI.DLL" ALIAS "EnumPageFilesA" ( _
pCallbacRoutine AS DWORD, _
BYVAL lpContext AS DWORD _
) AS LONG

DECLARE FUNCTION EnumPageFilesProc LIB "PSAPI.DLL" ALIAS "EnumPageFilesProcA" ( _
BYVAL pContext AS DWORD, _
BYVAL pPageFileInfo AS ENUM_PAGE_FILE_INFORMATION, _
lpFileName AS ASCIIZ _
) AS LONG


DECLARE FUNCTION EnumProcesses LIB "PSAPI.DLL" ALIAS "EnumProcesses" ( _
lpidProcess AS DWORD, _
BYVAL cb AS DWORD, _
cbNeeded AS DWORD _
) AS LONG


DECLARE FUNCTION EnumProcessModules LIB "PSAPI.DLL" ALIAS "EnumProcessModules" ( _
BYVAL hProcess AS DWORD, _
lphModule AS DWORD, _
BYVAL cb AS DWORD, _
lpcbNeeded AS DWORD _
) AS LONG


DECLARE FUNCTION GetDeviceDriverBaseName LIB "PSAPI.DLL" ALIAS "GetDeviceDriverBaseNameA" ( _
BYVAL ImageBase AS DWORD, _
lpBaseName AS ASCIIZ, _
BYVAL nSize AS DWORD _
) AS DWORD


DECLARE FUNCTION GetDeviceDriverFileName LIB "PSAPI.DLL" ALIAS "GetDeviceDriverFileNameA" ( _
BYVAL ImageBase AS DWORD, _
lpFileName AS ASCIIZ, _
BYVAL nSize AS DWORD _
) AS DWORD

DECLARE FUNCTION GetMappedFileName LIB "PSAPI.DLL" ALIAS "GetMappedFileNameA" ( _
BYVAL hProcess AS DWORD, _
BYVAL lpv AS DWORD, _
lpFileName AS ASCIIZ, _
BYVAL nSize AS DWORD _
) AS DWORD


DECLARE FUNCTION GetModuleBaseName LIB "PSAPI.DLL" ALIAS "GetModuleBaseNameA" ( _
BYVAL hProcess AS DWORD, _
BYVAL hModule AS DWORD, _
lpBaseName AS ASCIIZ, _
BYVAL nSize AS DWORD _
) AS DWORD


DECLARE FUNCTION GetModuleFileNameEx LIB "PSAPI.DLL" ALIAS "GetModuleFileNameExA" ( _
BYVAL hProcess AS DWORD, _
BYVAL hModule AS DWORD, _
lpFilename AS ASCIIZ, _
BYVAL nSize AS DWORD _
) AS DWORD


DECLARE FUNCTION GetModuleInformation LIB "PSAPI.DLL" ALIAS "GetModuleInformation" ( _
BYVAL hProcess AS DWORD, _
BYVAL hModule AS DWORD, _
lpmodinfo AS MODULEINFO, _
BYVAL cb AS DWORD _
) AS LONG


DECLARE FUNCTION GetPerformanceInfo LIB "PSAPI.DLL" ALIAS "GetPerformanceInfo" ( _
pPerformanceInformation AS PERFORMANCE_INFORMATION, _
cb AS DWORD _
) AS LONG


DECLARE FUNCTION GetProcessImageFileName LIB "PSAPI.DLL" ALIAS "GetProcessImageFileNameA" ( _
BYVAL hProcess AS DWORD, _
lpImageFileName AS ASCIIZ, _
BYVAL nSize AS DWORD _
) AS DWORD


DECLARE FUNCTION GetProcessMemoryInfo LIB "PSAPI.DLL" ALIAS "GetProcessMemoryInfo" ( _
BYVAL hProcess AS DWORD, _
ppsmemCounters AS PROCESS_MEMORY_COUNTERS, _
BYVAL cb AS DWORD _
) AS LONG

DECLARE FUNCTION GetWsChanges LIB "PSAPI.DLL" ALIAS "GetWsChanges" ( _
BYVAL hProcess AS DWORD, _
lpWatchInfo AS PSAPI_WS_WATCH_INFORMATION, _
BYVAL cb AS DWORD _
) AS LONG


DECLARE FUNCTION InitializeProcessForWsWatch ALIAS "InitializeProcessForWsWatch" ( _
BYVAL hProcess AS DWORD _
) AS LONG


DECLARE FUNCTION QueryWorkingSet LIB "PSAPI.DLL" ALIAS "QueryWorkingSet" ( _
BYVAL hProcess AS DWORD, _
pv AS DWORD, _
BYVAL cb AS DWORD _
) AS LONG


------------------

IP: Logged

JOSE ROCA
Member
posted November 14, 2002 09:30 PM     Click Here to See the Profile for JOSE ROCA     Edit/Delete Message   Reply w/Quote

' ==========================================================================
' Enumerating all processes.
' This is a translation of an example included in the MSDN documentation
' for PSAPI.
' ==========================================================================

#COMPILE EXE
#DIM ALL
#INCLUDE "win32api.inc"

SUB PrintProcessNameAndID (BYVAL processID AS DWORD)

LOCAL szProcessName AS ASCIIZ * %MAX_PATH
LOCAL hProcess AS DWORD
LOCAL hMod AS DWORD
LOCAL cbNeeded AS DWORD

szProcessName = "unknown"
'// Get a handle to the process.
hProcess = OpenProcess(%PROCESS_QUERY_INFORMATION OR _
%PROCESS_VM_READ, %FALSE, processID)
'// Get the process name.
IF ISFALSE hProcess THEN EXIT SUB
IF ISFALSE EnumProcessModules(hProcess, hMod, SIZEOF(hMod), cbNeeded) THEN EXIT SUB
GetModuleBaseName hProcess, hMod, szProcessName, SIZEOF(szProcessName)

'// Print the process name and identifier.
PRINT "Process ID: ", szProcessName, processID

CloseHandle hProcess

END SUB
' ==========================================================================

FUNCTION PBMAIN

'// Get the list of process identifiers.
DIM aProcesses(1024) AS DWORD
LOCAL cbNeeded AS DWORD
LOCAL cProcesses AS DWORD
LOCAL i AS DWORD

IF ISFALSE EnumProcesses(aProcesses(LBOUND(aProcesses)), _
(UBOUND(aProcesses)- LBOUND(aProcesses) + 1) * 4, cbNeeded) THEN EXIT FUNCTION

'// Calculate how many process identifiers were returned.
cProcesses = cbNeeded \ 4

'// Print the name and process identifier for each process.

FOR i = 0 TO cProcesses
PrintProcessNameAndId aProcesses(i)
NEXT

END FUNCTION


------------------

IP: Logged

JOSE ROCA
Member
posted November 14, 2002 09:32 PM     Click Here to See the Profile for JOSE ROCA     Edit/Delete Message   Reply w/Quote

' ==========================================================================
' Enumerating allmodules for a process.
' This is a translation of an example included in the MSDN documentation
' for PSAPI.
' ==========================================================================

SUB PrintModules (BYVAL processID AS DWORD)

DIM hMods(1024) AS DWORD
LOCAL hProcess AS DWORD
LOCAL cbNeeded AS DWORD
LOCAL i AS LONG
LOCAL szModName AS ASCIIZ * %MAX_PATH

'// Print the process identifier.
PRINT "Process ID: ", processID

'// Get a list of all the modules in this process.
hProcess = Openprocess (%PROCESS_QUERY_INFORMATION OR _
%PROCESS_VM_READ, %FALSE, processID)

IF hProcess = 0 THEN EXIT SUB

IF ISFALSE EnumProcesses(hMods(LBOUND(hMods)), _
(UBOUND(hMods)- LBOUND(hMods) + 1) * 4, cbNeeded) THEN EXIT SUB

FOR i = 0 TO cbNeeded \ 4
'// Get full path to the module's file
IF GetModuleFileNameEx(hProcess, hMods(i), szModName, SIZEOF(szModName)) THEN
'// Print the module name and handle value.
PRINT szModName, hMods(i)
END IF
NEXT

CloseHandle hProcess

END SUB
' ==========================================================================

FUNCTION PBMAIN

DIM aProcesses(1024) AS DWORD
LOCAL cbNeeded AS DWORD
LOCAL cProcesses AS DWORD
LOCAL i AS LONG

IF ISFALSE EnumProcesses(aProcesses(LBOUND(aProcesses)), _
(UBOUND(aProcesses)- LBOUND(aProcesses) + 1) * 4, cbNeeded) THEN EXIT FUNCTION

'// Calculate how many process identifiers were returned.
cProcesses = cbNeeded \ 4

'// Print the name of the module for each process.

FOR i = 0 TO cProcesses
PrintModules aProcesses(i)
NEXT

END FUNCTION


------------------

IP: Logged

JOSE ROCA
Member
posted November 14, 2002 09:35 PM     Click Here to See the Profile for JOSE ROCA     Edit/Delete Message   Reply w/Quote

' ==========================================================================
' Collecting memory usage information for a process.
' This is a translation of an example included in the MSDN documentation
' for PSAPI.
' ==========================================================================

#COMPILE EXE
#DIM ALL
#INCLUDE "win32api.inc"

SUB PrintMemoryInfo (BYVAL processID AS DWORD)

LOCAL hProcess AS DWORD
LOCAL pmc AS PROCESS_MEMORY_COUNTERS

'// Print the process identifier
PRINT "Process ID: "processID

'// Print information about the memory usage of the process.
hProcess = Openprocess (%PROCESS_QUERY_INFORMATION OR _
%PROCESS_VM_READ, %FALSE, processID)

IF hProcess = 0 THEN EXIT SUB

IF (GetProcessMemoryInfo(hProcess, pmc, SIZEOF(pmc))) THEN
PRINT "PageFaultCount: ", pmc.PageFaultCount
PRINT "PeakWorkinSetSize: ", pmc.PeakWorkingSetSize
PRINT "WorkingSetSize: "pmc.WorkingSetSize
PRINT "QuotaPeakPagegPoolUsage: ", pmc.QuotaPeakPagedPoolUsage
PRINT "QuotaPagedPoolUsage: ", pmc.QuotaPagedPoolUsage
PRINT "QuotaPeakNonPagedPoolUsage: ", pmc.QuotaPeakNonPagedPoolUsage
PRINT "QuotaNonPagedPoolUsage: ", pmc.QuotaNonPagedPoolUsage
PRINT "PageFileUsage: ", pmc.PageFileUsage
PRINT "PeakPageFileUsage: ", pmc.PeakPageFileUsage
END IF

CloseHandle hProcess

END SUB
' ==========================================================================

FUNCTION PBMAIN

DIM aProcesses(1024) AS DWORD
LOCAL cbNeeded AS DWORD
LOCAL cProcesses AS DWORD
LOCAL i AS LONG

'// Get the list of process identifiers
IF ISFALSE EnumProcesses(aProcesses(LBOUND(aProcesses)), _
(UBOUND(aProcesses) - LBOUND(aProcesses) + 1) * 4, cbNeeded) THEN EXIT FUNCTION

'// Calculate how many process identifiers were returned.
cProcesses = cbNeeded \ 4

'// Print the memory usage for each process
FOR i= 0 TO cProcesses
PrintMemoryInfo aProcesses(i)
NEXT

END FUNCTION


------------------

IP: Logged

JOSE ROCA
Member
posted November 14, 2002 09:37 PM     Click Here to See the Profile for JOSE ROCA     Edit/Delete Message   Reply w/Quote

' ==========================================================================
' Enumerating all device drivers.
' The main function obtains a list of load addresses by using the
' EnumDeviceDrivers function. For each address, main calls the
' PrintDeviceDriverbaseName or PrintDeviceDriverFileName passing the driver
' load address.
' ==========================================================================

#COMPILE EXE
#DIM ALL
#INCLUDE "win32api.inc"

' ==========================================================================
SUB PrintDeviceDriverBaseName (BYVAL dwImageBase AS DWORD)

LOCAL szBaseName AS ASCIIZ * %MAX_PATH

PRINT "Driver address: ", dwImageBase;
GetDeviceDriverBaseName dwImageBase, szBaseName, SIZEOF(szBaseName)
PRINT szBaseName

END SUB
' ==========================================================================

' ==========================================================================
SUB PrintDeviceDriverFileName (BYVAL dwImageBase AS DWORD)

LOCAL szFileName AS ASCIIZ * %MAX_PATH

PRINT "Driver address: ", dwImageBase;
GetDeviceDriverFileName dwImageBase, szFileName, SIZEOF(szFileName)
PRINT szFileName

END SUB
' ==========================================================================

FUNCTION PBMAIN

DIM aDrivers(1024) AS DWORD
LOCAL cbNeeded AS DWORD
LOCAL cAddresses AS DWORD
LOCAL i AS LONG

'// Get the list of device drivers addresses
IF ISFALSE EnumDeviceDrivers(aDrivers(LBOUND(aDrivers)), _
(UBOUND(aDrivers) - LBOUND(adrivers) + 1) * 4, cbNeeded) THEN EXIT FUNCTION

'// Calculate how many addresses were returned
cAddresses = cbNeeded \ 4

'// Print the base names of the drivers
FOR i = 0 TO cAddresses
' PrintDeviceDriverBaseName aDrivers(i)
PrintDeviceDriverFileName aDrivers(i)
NEXT

END FUNCTION


------------------

IP: Logged

José Roca
Member
posted January 28, 2005 08:30 PM     Click Here to See the Profile for José Roca     Edit/Delete Message   Reply w/Quote
I changed my password and now I'm not able to edit my post. The declare for
the function EnumPageFilesProc should be:

DECLARE FUNCTION EnumPageFilesProc LIB "PSAPI.DLL" ALIAS "EnumPageFilesProcA" ( _
BYVAL pContext AS DWORD, _
pPageFileInfo AS ENUM_PAGE_FILE_INFORMATION, _
lpFileName AS ASCIIZ _
) AS LONG

------------------

IP: Logged

José Roca
Member
posted September 23, 2006 09:45 PM     Click Here to See the Profile for José Roca     Edit/Delete Message   Reply w/Quote
Updated headers and examples available in my forum:

http://www.forum.it-berater.org/index.php?topic=347.0

------------------
Website: http://com.it-berater.org
SED Editor, TypeLib Browser, COM Wrappers.
Forum: http://www.forum.it-berater.org

IP: Logged

All times are EasternTime (US)

next newest topic | next oldest topic

Administrative Options: Close Topic | Archive/Move | Delete Topic
Post New Topic  Post A Reply
Hop to:

Contact Us | PowerBASIC BASIC Compilers

Copyright © 1999-2006 PowerBASIC, Inc. All Rights Reserved.


Ultimate Bulletin Board 5.45c