宽字符和 win32::api

编程入门 行业动态 更新时间:2024-10-27 10:24:55
本文介绍了宽字符和 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

本文发布于:2023-10-08 13:50:41,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1472819.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:字符   api

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!