Hi Wyrdweaver,
When I run that batch file (as 'yrt.bat') I get the following output, followed by a GPF:
C:\_32\pscrpt\inline>yrt.bat string[21] = 'perl -x -S yrt.bat '
Here's the same batch file using Inline::C (which you could install and use, since you have MinGW) instead of Win32::API:
@rem = '--*-Perl-*-- @echo off if "%OS%" == "Windows_NT" goto WinNT perl -x -S "%0" %1 %2 %3 %4 %5 %6 %7 %8 %9 goto endofperl :WinNT perl -x -S %0 %* if NOT "%COMSPEC%" == "%SystemRoot%\system32\cmd.exe" goto endofperl if %errorlevel% == 9009 echo You do not have Perl in your PATH. if errorlevel 1 goto script_failed_so_exit_with_non_zero_val 2>nul goto endofperl @rem '; #!/usr/bin/perl -w #line 15 #use Inline C => Config => # BUILD_NOISY => 1; # See compilation output use Inline C => <<'EOC'; SV * wrap_GetCommandLine() { return newSVpv(GetCommandLine(), 0); } EOC my $string = wrap_GetCommandLine(); print "string[".length($string)."] = '$string'\n"; # ------ padding ----------------------------------------------------- +--------------------------------- __END__ :endofperl
The first time you run that there's some compilation takes place.Subsequent runs of the batch file will not require any compilation unless the actual Inline::C code is changed, or the name of the batch file is changed. Running that batch file (as try.bat), I get:
C:\_32\pscrpt\inline>try.bat string[20] = 'perl -x -S try.bat '
This time there's no GPF - I don't know why try.bat reports one less trailing space than yrt.bat.

Hope this helps.

Cheers,
Rob
Update:Or, if you want to modularise it (which would make better sense) here's a very minimalistic approach:
Makefile.PL
use ExtUtils::MakeMaker; my %options = %{ { 'NAME' => 'Win32::GetCommandLine', 'VERSION' => '0.01' } }; WriteMakefile(%options); # Remove the Makefile dependency. Causes problems on a few systems. sub MY::makefile { '' }
GetCommandLine.xs
#include "EXTERN.h" #include "perl.h" #include "XSUB.h" SV * wrap_GetCommandLine() { return newSVpv(GetCommandLine(), 0); } MODULE = Win32::GetCommandLine PACKAGE = Win32::GetCommandLine PROTOTYPES: DISABLE SV * wrap_GetCommandLine ()
t/test.t
use Win32::GetCommandLine; print "1..1\n"; my $string = Win32::GetCommandLine::wrap_GetCommandLine(); if($string =~ /perl/) {print "ok 1\n"} else {print "not ok 1\n"}
Win32/GetCommandLine.pm
package Win32::GetCommandLine; require DynaLoader; @ISA = qw(DynaLoader); $VERSION = '0.01'; bootstrap Win32::GetCommandLine $VERSION; 1;

In reply to Re: Win32::API Memory Exception with GetCommandLine() (which returns a static string) by syphilis
in thread Win32::API Memory Exception with GetCommandLine() (which returns a static string) by Wyrdweaver

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.