in reply to handlecount of win32 process

#! perl -slw use strict; use Win32::API; Win32::API->Import( 'Kernel32', 'HANDLE GetCurrentProcess( )' ); Win32::API->Import( 'Kernel32', 'BOOL GetProcessHandleCount(HANDLE h, LPDWORD c)' ); my $hProcess = GetCurrentProcess(); my $count = 0; GetProcessHandleCount( $hProcess, $count ) or die $^E; printf "This process is using %d handles\n", $count; __END__ P:\test>479539 This process is using 16 handles

Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
Lingua non convalesco, consenesco et abolesco. -- Rule 1 has a caveat! -- Who broke the cabal?
"Science is about questioning the status quo. Questioning authority".
The "good enough" maybe good enough for the now, and perfection maybe unobtainable, but that should not preclude us from striving for perfection, when time, circumstance or desire allow.

Replies are listed 'Best First'.
Re^2: handlecount of win32 process
by slloyd (Hermit) on Jul 30, 2005 at 01:49 UTC
    Thanks a bunch! I even asked a bunch of windows programmers at work and no one could tell me how. DotNet programmers seem to only know the interface, not the underlying language anymore...
Re^2: handlecount of win32 process
by slloyd (Hermit) on Aug 01, 2005 at 14:20 UTC
    Here is my implimentation of the same code..
    #! perl -slw use strict; use Win32::API; my $hProcess = getCurrentProcess(); my $cnt=getProcessHandleCount($hProcess); print "handle count=$cnt\n"; ############### sub getCurrentProcess{ my $GetCurrentProcess = new Win32::API("Kernel32", "GetCurrentProc +ess", [], 'N') || return $^E; my $hProcess=$GetCurrentProcess->Call(); return $hProcess; } ############### sub getProcessHandleCount{ my $hProcess = shift; print "hProcess=$hProcess\n"; my $GetProcessHandleCount = new Win32::API("Kernel32", "GetProcess +HandleCount", ['N','P'], 'N') || return $^E; my $rtn=' 'x12; my $ok=$GetProcessHandleCount->Call( $hProcess,$rtn); my $count=unpack("II", $rtn); return $count; }