Wide char and win32 :: api

In perl, I use this code to invoke a shellabout dialog using win32 :: api:

my $shellAbout = Win32::API->new('Shell32', 'int ShellAboutA(HWND hWnd, LPCTSTR szApp, LPCTSTR szOtherStuff, HICON hIcon)');  
    $shellAbout->Call (0, 'perl-reguser', 'Editor del registro de usuario', 0);

      

The above works as expected, but when I try to use the unicode version of shellabout:

my $shellAbout = Win32::API->new('Shell32', 'int ShellAboutW(HWND hWnd, LPCTSTR szApp, LPCTSTR szOtherStuff, HICON hIcon)');  
    $shellAbout->Call (0, 'perl-reguser', 'Editor del registro de usuario', 0);

      

Rows are not displayed. I have the following:

use utf8;
use Encode;
# ..
binmode (STDOUT, ":encoding(utf8)");

      

any ideas?

+1


source to share


1 answer


For calls, there W

LPCTSTR

must be a null character string encoded using UTF-16le.



use strict;
use warnings;

use utf8;   # Source code is encoded using UTF-8.

use Encode     qw( encode );
use Win32::API qw( );

my $shellAbout;

sub ShellAbout {
   my ($hWnd, $szApp, $szOtherStuff, $hIcon) = @_;

   $shellAbout ||= Win32::API->new('Shell32', 'int ShellAboutW(HWND hWnd, LPCTSTR szApp, LPCTSTR szOtherStuff, HICON hIcon)');

   $szApp = encode('UTF-16le', $szApp . "\0");
   $szOtherStuff = encode('UTF-16le', $szOtherStuff . "\0") if defined($szOtherStuff);

   $hWnd  //= 0;
   $hIcon //= 0;   

   return $shellAbout->Call($hWnd, $szApp, $szOtherStuff, $hIcon);
}


ShellAbout(undef, 'perl-reguser', 'Editor del registro de usuario', undef)
   or die($^E);

      

+2


source







All Articles