I'm trying to figure out how to read the result of GetCommandLineW
in Perl.
I know that is should return a string beginning with "
when invoked under PowerShell, but I can't seem to extract more than one character.
The following snippet loads the GetCommandLineW
function and attempts to invoke it.✱
#! /usr/bin/env perl
use strict;
use warnings;
use Win32;
use Data::Dumper;
use Win32::API;
my $GetCommandLineW = Win32::API::More->new(
"kernel32", "LPWSTR GetCommandLineW()"
);
die unless $GetCommandLineW;
print Dumper($GetCommandLineW->Call());
prints
$VAR1 = '"';
I get the same thing if I replace LPWSTR
in the command line with char *
or anything else that's stringlike. I get back a pointer as a decimal number if I use int
or a garbage value as the return type.
Is there a way that I can indicate to the Win32::API
module that I am intending to read back a UTF-16 LE string or a way to "convince" it to put all the contents of said string into a Perl scalar.
I'm okay if there some encoding issues in the resulting scalar that need cleaning up immediately after calling $GetCommandLineW->Call()
as long as all the data is there.
✱ The shebang is there so the same script can be invoked with or without Cygwin.