[FFI newbie] Windows process info from Squeak
Valdas Bucinskas
valdas.bucinskas at ipsistemos.lt
Thu Feb 2 11:30:53 UTC 2006
Hello,
Wow, your examples are really interesting and helps incredibly much.
I modified your your last example slightly, incorporating RAMs used by the
process. And then tried to find the .exe that calls the process. It appears,
the method GetModuleBaseName from psapi.dll should be used, which is
described in
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/perfmon/bas
e/getmodulebasename.asp.
It gives the method declaration is
DWORD GetModuleBaseName(
HANDLE hProcess,
HMODULE hModule,
LPTSTR lpBaseName,
DWORD nSize
);
What I miss now is the knowledge, how do I convert types from c++ like into
Sueak ones. I guess hProcess corresponds to Win32Handle, lpBaseName
corresponds to char*, and nSize corresponds to long. GetModuleBaseName
returns long.
1. But what does hModule correspond to?
My guess
<apicall: long 'GetModuleBaseName' (Win32Handle Win32Handle char* long)
module: 'psapi.dll'>
throughs Error 13, which is 'The data is invalid.'
2. Should a class similar to Win32Handle be created in order to hModule
typecasting work?
================
Modified piece of code (stopped while trying to make the apiGetProcessName
work ):
"use the process IDs to open the processes and to query the amount of
resources they use."
oc := OrderedCollection new.
handleArray
do: [:idx |
processHandle := interface
getProcessHandleWithAccessRights: 1024
inherit: true
processId: idx.
processHandle notNil
ifTrue: [memRec := Win32ProcessMemoryCounters new.
interface
apiGetProcessMemoryInfoFor: processHandle
into: memRec
descriptorSize: memRec class byteSize.
processName := ''.
processInfo := Dictionary new.
processInfo at: 'PID' put: idx.
processInfo
at: 'GDI Objects'
put: (interface apiGetGuiResources: processHandle type: 0).
processInfo
at: 'USER Objects'
put: (interface apiGetGuiResources: processHandle type: 1).
processInfo at: 'Mem Usage' put: memRec WorkingSetSize.
processInfo at: 'Process Name' put: nil.
"(interface apiGetProcessName: processHandle module: nil into: processName
size: 40)."
oc add: processInfo.
interface closeHandle: processHandle]].
^ oc
"It is a nice idea to compare this with the data that are shown in the
Task Manager
Yeah, it is the same! It is like a little Task Manager in Squeak!
"
Best regards,
Valdas Bucinskas
More information about the Squeak-dev
mailing list
|