本文介绍了宽字符和 win32::api的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在 perl 中,我使用此代码使用 win32::api 调用 shellabout 对话框:
In perl I'm using this code to call the 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);以上按预期工作,但是当我尝试使用 shellabout 的 unicode 版本时:
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);不显示字符串.我声明了以下内容:
The strings are not displayed. I have the following declared:
use utf8; use Encode; # .. binmode (STDOUT, ":encoding(utf8)");有什么想法吗?
推荐答案对于 W 调用,LPCTSTR 必须是使用 UTF-16le 编码的以 NUL 结尾的字符串.
For W calls, LPCTSTR must be a NUL-terminated 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);更多推荐
宽字符和 win32::api
发布评论