Very nice and Very handy package.
I'm having a problem, however... :-)
In short, I'm trying to use Win32::API to call CreateProcess.
All is well except for the LPSTARTUPINFO and LPPROCESS_INFORMATION parms I pass into the call. If I create these using pack(...) for the correct number of bytes, it works fine and I can get the PID back out of the PROCESS_INFORMATION object (my ultimate goal).
If, however, I create these parms using the Win32::API::Struct->new( 'STARTUPINFO' ) approach, the call fails. I'm even setting the .cb field to the size of the structure. The error I get back (using Win32::GetLastError()) is "Invalid access to memory location". Here's the function call I'm making (same in both cases):
<-----------snip------------>
# version 1 - succeeds
my $si = pack( "L17", ((0) x 17) );
$si = pack( "LL16", length( $si ), ((0) x 16 ) );
my $pi = pack( "L4", ((0) x 4 ) );
# version 2 - fails
my $si = Win32::API::Struct->new( "STARTUPINFO" );
$si->{cb} = $si->sizeof();
my $pi = Win32::API::Struct->new( "PROCESS_INFORMATION" );
my $retval =
CreateProcess( "c:\\winnt\\notepad.exe",
0, # unused - cmdline ptr, unused
0, # unused - proc attributes ptr
0, # unused - thread attributes ptr
0, # unused - inherit handles
0, # unused - creation flags
0, # unused - env pointer
0, # unused - current dir ptr
$si,
$pi
);
<-----------snip------------>
Should CreateProcess be called the same way in both cases? When a ->new('STARTUPINFO') is called, is the memory zeroed-out upon creation? Any idea why the pack version succeeds and the Struct verion fails?
TIA!
D. Smith
-
Are you posting in the right place? Check out Where do I post X? to know for sure.
-
Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
<code> <a> <b> <big>
<blockquote> <br /> <dd>
<dl> <dt> <em> <font>
<h1> <h2> <h3> <h4>
<h5> <h6> <hr /> <i>
<li> <nbsp> <ol> <p>
<small> <strike> <strong>
<sub> <sup> <table>
<td> <th> <tr> <tt>
<u> <ul>
-
Snippets of code should be wrapped in
<code> tags not
<pre> tags. In fact, <pre>
tags should generally be avoided. If they must
be used, extreme care should be
taken to ensure that their contents do not
have long lines (<70 chars), in order to prevent
horizontal scrolling (and possible janitor
intervention).
-
Want more info? How to link
or How to display code and escape characters
are good places to start.