in reply to Win32::API Memory Exception with GetCommandLine() (which returns a static string)
Here's the same batch file using Inline::C (which you could install and use, since you have MinGW) instead of Win32::API:C:\_32\pscrpt\inline>yrt.bat string[21] = 'perl -x -S yrt.bat '
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:@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
This time there's no GPF - I don't know why try.bat reports one less trailing space than yrt.bat.C:\_32\pscrpt\inline>try.bat string[20] = 'perl -x -S try.bat '
GetCommandLine.xsuse 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 { '' }
t/test.t#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 ()
Win32/GetCommandLine.pmuse 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"}
package Win32::GetCommandLine; require DynaLoader; @ISA = qw(DynaLoader); $VERSION = '0.01'; bootstrap Win32::GetCommandLine $VERSION; 1;
|
|---|