Hello Boris,
Thanks man! You helped me greatly, saving some weaks (months) of tedious work. Your examples were the enormous help. You could be a tallented teacher :)
Best regards, Valdas Bucinskas
-----Original Message----- From: squeak-dev-bounces@lists.squeakfoundation.org [mailto:squeak-dev-bounces@lists.squeakfoundation.org]On Behalf Of "Boris Gartner" Sent: Thursday, February 02, 2006 5:12 PM To: The general-purpose Squeak developers list Subject: RE: [FFI newbie] Windows process info from Squeak
No please try this:
1. add this api method to Win32Window:
apiGetModuleBaseName: hProcess module: hModule into: lpString bufferSize: size <apicall: long 'GetModuleBaseNameA' (Win32Handle Win32Handle char* long) module: 'psapi.dll'> ^self externalCallFailed
2. Ensure that you open the process handle with access rights 16r410 (this is PROCESS_QUERY_INFORMATION | PROCESS_VM_READ, the access right alone PROCESS_QUERY_INFORMATION does not allow you tho read the name) (The processes System, Idle and some others will not tell you their names anyway)
3. Do something like this:
handleArray do: [:idx | processHandle := interface getProcessHandleWithAccessRights: 16r410 inherit: true processId: idx. processHandle notNil ifTrue: [ | buffer processName cnt | buffer := ByteArray new: 80. interface apiGetModuleBaseName: processHandle module: nil into: buffer bufferSize: 80. processName := WriteStream on: (String new: 80). cnt := 1. [i <= 80 and: [(buffer at: cnt) ~= 0]] whileTrue: [processName nextPut: (Character value: (buffer at: cnt)). cnt := cnt + 1]. processName := processName contents. oc add: (Array with: idx with: (interface apiGetGuiResources: processHandle type: 0) with: (interface apiGetGuiResources: processHandle type: 1) with: processName).
interface closeHandle: processHandle. ] ].
When you have to provide buffers that are filled with some information, it is always a good choice to use ByteArrays of suitable size. You can always convert a ByteArray into a number or into a string.
Hope this helps, Boris