It seems that Win32::API::Struct::Sizeof is returning the wrong size. Setting it to 296 and your code works:

#! perl -slw use strict; use Data::Dumper; use Win32::API; Win32::API::Struct->typedef( PROCESSENTRY32 => qw{ LONG dwSize; LONG cntUsage; LONG th32ProcessID; LONG th32DefaultHeapID; LONG th32ModuleID; LONG cntThreads; LONG th32ParentProcessID; LONG pcPriClassBase; LONG dwFlags; CHAR szExeFile[260]; }) ; Win32::API->Import('kernel32.dll', "HANDLE CreateToolhelp32Snapshot(DW +ORD dwFlags,DWORD th32ProcessID)"); Win32::API->Import('kernel32.dll', "BOOL Process32First( HANDLE hSnaps +hot, LPPROCESSENTRY32 lppe )" ); Win32::API->Import('kernel32.dll', "BOOL Process32Next( HANDLE hSnapsh +ot, LPPROCESSENTRY32 lppe )" ); my $TH32CS_SNAPPROCESS = 0x2; $^W=0; my $Snapshot = undef; my $ProcessInfo = Win32::API::Struct->new('PROCESSENTRY32') or die $^E +; $Snapshot = CreateToolhelp32Snapshot($TH32CS_SNAPPROCESS, 0) or die $^ +E; $ProcessInfo->{dwSize} = 296; #Win32::API::Struct::sizeof ($ProcessInf +o); my $Sucess = Process32First( $Snapshot, $ProcessInfo) or die $^E; print "First Process : $ProcessInfo->{szExeFile}\n"; #are returning no +thing #print Dumper $ProcessInfo; while( Process32Next( $Snapshot, $ProcessInfo ) ) { print $ProcessInfo->{szExeFile}; # print Dumper $ProcessInfo; } __END__ P:\test>446283 First Process : [System Process] System SMSS.EXE CSRSS.EXE WINLOGON.EXE SERVICES.EXE LSASS.EXE SVCHOST.EXE SVCHOST.EXE SVCHOST.EXE SVCHOST.EXE vsmon.exe EXPLORER.EXE zlclient.exe TASKMGR.EXE mdm.exe CMD.EXE CMD.EXE CMD.EXE CMD.EXE CMD.EXE CMD.EXE opera.exe perl.exe

I worked out what was wrong by adding some error checking which produced the error text: "The program issued a command but the command length is incorrect" from the call to Process32First().


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?

In reply to Re: Win32::API Help ! by BrowserUk
in thread Win32::API Help ! by shonorio

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.