ASPN ActiveState Programmer Network
ActiveState
/ Home / Perl / PHP / Python / Tcl / XSLT /
/ Safari / My ASPN /
Cookbooks | Documentation | Mailing Lists | Modules | News Feeds | Products | User Groups


Recent Messages
List Archives
About the List
List Leaders
Subscription Options

View Subscriptions
Help

View by Topic
ActiveState
.NET Framework
Open Source
Perl
PHP
Python
Tcl
Web Services
XML & XSLT

View by Category
Database
General
SOAP
System Administration
Tools
User Interfaces
Web Programming
XML Programming


MyASPN >> Mail Archive >> perl-win32-admin
perl-win32-admin
Problem Invoking WinAPI CreateProcess
by Eyal Meltzer other posts by this author
Jun 4 2009 3:19AM messages near this date
view in the new Beta List Site
error 0x80004002 | Re: Problem Invoking WinAPI CreateProcess
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";
Thread:
Eyal Meltzer
kenneth
Eyal Meltzer

Privacy Policy | Email Opt-out | Feedback | Syndication
© ActiveState Software Inc. All rights reserved