----- Original Message -----
From: "Xiao Yafeng" <xyf.x...@gmail.com>
To: "inline" <inline@perl.org>
Cc: "Sisyphus" <sisyph...@optusnet.com.au>
Sent: Wednesday, September 07, 2011 2:28 AM
Subject: strange line
I wrote a simple snippet to list processes name and pid on windows. but the
output returns a strange line. below is the code:
use strict;
use warnings;
use Inline C => DATA =>
LIBS => '-luser32 -lkernel32 -lpsapi';
my $a = process_list();
map { print; print get_proc_name($_);print "\n"; } @{$a};
__END__
__C__
#include <windows.h>
#include <stdio.h>
#include <tchar.h>
#include <psapi.h>
char* get_proc_name( int processID )
{
TCHAR szProcessName[MAX_PATH] = TEXT("<unknown>");
HANDLE hProcess = OpenProcess( PROCESS_QUERY_INFORMATION |
PROCESS_VM_READ,
FALSE, processID );
if (NULL != hProcess )
{
HMODULE hMod;
DWORD cbNeeded;
if ( EnumProcessModules( hProcess, &hMod, sizeof(hMod),
&cbNeeded) )
{
GetModuleBaseName( hProcess, hMod, szProcessName,
sizeof(szProcessName)/sizeof(TCHAR) );
}
}
CloseHandle( hProcess );
return szProcessName;
}
SV* process_list(){
DWORD aProcesses[1024], cbNeeded, cProcesses;
unsigned int i;
EnumProcesses( aProcesses, sizeof(aProcesses), &cbNeeded );
cProcesses = cbNeeded / sizeof(DWORD);
AV* AV_procs = newAV();
for ( i = 0; i < cProcesses; i++ )
{
if( aProcesses[i] != 0 )
{
av_push(AV_procs, newSViv( aProcesses[i] ) );
}
}
return newRV_inc(AV_procs);
}
__OUTPUT__
C:\>perl test.pl
4P ?F > <== strange line
292<unknown>
372<unknown>
432<unknown>
Haven't yet had a chance to take a thorough look at this.
I inserted the following near the beginning of your script:
use Inline C => Config =>
BUILD_NOISY => 1;
That way you get to see any compiler warnings that are emitted during the C
compilation, and with my cc-4.5.2 build of perl-5.14 I saw:
try_pl_f4a3.xs: In function 'get_proc_name':
try_pl_f4a3.xs:35:1: warning: function returns address of local variable
try_pl_f4a3.xs: In function 'process_list':
try_pl_f4a3.xs:57:5: warning: passing argument 2 of 'Perl_newRV' from
incompatible pointer type
C:\MinGW\perl\lib\CORE/proto.h:2567:19: note: expected 'struct SV * const'
but argument is of type 'struct AV *'
Whether there's anything relevant there, I don't know.
I get different output to you, of course. But in the middle of the output I
also got one odd-looking line:
1348┤aæ☻↑:ñ $ ↑:ñ ~↑☻
When I switched to a gcc-3.4.5 build of perl-5.12, I found out what 1348
really was:
1348TomTomHOMERunner.exe
But then I got a strange line at the beginning of the output:
4ð¬─w4§Å ↑
whereas, with gcc-4.5.2, that had been:
4<unknown>
This is probably a good question for somewhere like perlmonks, where there's
people with a good understanding of windows itself.
Cheers,
Rob