Rod Butcher wrote:

>>my $PE32 = pack 'LLLLLLLLLZ', 296, 0, 0, 0, 0, 0, 0, 0, 0, ' ' x 259 . "\0";
>>
>># BOOL WINAPI Process32First(HANDLE hSnapshot, LPPROCESSENTRY32 lppe);
>>
>>Win32::API->Import('kernel32', 'Process32First', 'IP', 'I') or
>>  die "import CreateToolhelp32Snapshot: $!($^E)";
>>
>>my $ret = Process32First ($hProcessSnap, $PE32) or
>>  die "Process32First: $! $(^E)";
>>
>>my @PE32 = unpack 'LLLLLLLLLZ', $PE32;
>># print Data::Dumper->Dump([EMAIL PROTECTED], [qw([EMAIL PROTECTED])]);
>>
> 
> Thanks $Bill and Sisyphus. if I hardcode szExeFile and dwSize (struct 
> length), I then get error 18 (no more files / failed to return data) in 
> Process32First. This occurs whether I use pack or Win32::API::Struct to 
> define the structure. Would this mean I'm not getting a valid handle to 
> the snapshot or not passing it correctly to Process32First ? (code is 
> shown in my first post).

The code above worked for me - $ret should be a 1 if it worked, 0 otherwise.
I left off the first code snippet:

Win32::API->Import('kernel32',
  'HANDLE CreateToolhelp32Snapshot(DWORD dwFlags, DWORD th32ProcessID)')
  or die "import CreateToolhelp32Snapshot: $!($^E)";

use constant TH32CS_SNAPTHREAD => 0x4;
my $hProcessSnap = CreateToolhelp32Snapshot (TH32CS_SNAPTHREAD, 0);
die "CreateToolhelp32Snapshot: $!($^E)" if $hProcessSnap == -1;
print Data::Dumper->Dump([$hProcessSnap], [qw($hProcessSnap)]);

My results:

$hProcessSnap = 1980;
$PE32 = '(☺                                   ';
[EMAIL PROTECTED] = [
  296,
  62,
  0,
  669,
  0,
  0,
  0,
  48,
  0,
  ''
];
_______________________________________________
Perl-Win32-Users mailing list
Perl-Win32-Users@listserv.ActiveState.com
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs

Reply via email to