Hi
I’m tying to call the winapi 'CreateProcess' – but it doesn’t seems to work
can you tell me if im doing something wrong
Win32::API::Struct->typedef( STARTUPINFO => qw{
DWORD cb;
LPTSTR lpReserved;
LPTSTR lpDesktop;
LPTSTR lpTitle;
DWORD dwX;
DWORD dwY;
DWORD dwXSize;
DWORD dwYSize;
DWORD dwXCountChars;
DWORD dwYCountChars;
DWORD dwFillAttribute;
DWORD dwFlags;
WORD wShowWindow;
WORD cbReserved2;
LPBYTE lpReserved2;
HANDLE hStdInput;
HANDLE hStdOutput;
HANDLE hStdError;
} );
Win32::API::Struct->typedef( PROCESS_INFORMATION => qw{
HANDLE hProcess;
HANDLE hThread;
DWORD dwProcessId;
DWORD dwThreadId;
});
my $cmd = "c:\\WINDOWS\\notepad.exe";
my $dir = ".";
#### import an API that uses this structures
Win32::API->Import( 'kernel32', 'BOOL CreateProcess(LPCTSTR
lpApplicationName, LPTSTR lpCommandLine, LPVOID lpProcessAttributes, LPVOID
lpThreadAttributes, BOOL bInheritHandles, DWORD dwCreationFlags, LPVOID
lpEnvironment, LPCTSTR lpCurrentDirectiry, LPSTARTUPINFO lpStartupInfo,
LPPROCESS_INFORMATION lpProcessInformation)');
my $si = Win32::API::Struct->new( 'STARTUPINFO' );
my $pi = Win32::API::Struct->new( 'PROCESS_INFORMATION' );
if(!defined($si) || !defined($pi)) {
die "Can't import API CreateProcess: $!\n";
}
### call the function passing our structure object
CreateProcess(undef, $cmd, undef, undef, 0, 0, undef, $dir, $si, $pi);
print "CreateProcess Try1 : $pi->{dwProcessId}, $pi->{dwThreadId}\n";
#(LPCTSTR lpApplicationName, LPTSTR lpCommandLine, LPVOID
lpProcessAttributes, LPVOID lpThreadAttributes, BOOL bInheritHandles, DWORD
dwCreationFlags, LPVOID lpEnvironment,
#LPCTSTR lpCurrentDirectiry, LPSTARTUPINFO lpStartupInfo,
LPPROCESS_INFORMATION lpProcessInformation)');
#### use NEW an API that uses this structures
my $CreateProcess = Win32::API->new('kernel32', 'CreateProcess',
'PPPPNNPPPP' , 'N');
if(!defined($CreateProcess)) {
die "Can't import API CreateProcess: $!\n";
}
my $rtn = $CreateProcess->Call(undef, $cmd, undef, undef, 0, 0, undef, $dir,
$si, $pi);
print "rtn = $rtn\n";
print "CreateProcess Try2 : $pi->{dwProcessId}, $pi->{dwThreadId}\n";
_______________________________________________
Perl-Win32-Admin mailing list
[email protected]
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs