
[英]Unexpected behavior when placing Unicode text on Clipboard with NULL owner window
[英]unexpected logiclib behavior when testing string returned by system plugin
我通过使用类似于上一个问题的答案的代码,通过System插件获取系统信息。 API函数非常相似,除了它返回(或不返回)宽字符字符串。
在属于域成员的计算机上使用该脚本时,我无法理解为什么logiclib测试始终通过测试的${else}
分支。 以下捕获显示$1
不为空:
在阅读更多NetGetDCName参考时,我认为最好检查函数返回的值而不是宽字符字符串指针。 我有点困惑,为什么我的${If} 0 <> $1
总是失败? 在这种情况下,我已经检查了不是$1
等于0
的域成员的虚拟机。 我想然后${IfThen}
测试来释放内存也是错误的。
这是示例代码:
!include "logiclib.nsh"
outfile "hello2.exe"
!define DEBUG `System::Call kernel32::OutputDebugString(ts)`
section
Call GetDCName
pop $0
Messagebox MB_OK "DCName=$0"
sectionEnd
Function GetDCName
;Push the domain controler name to the stack (or an empty string if no dc)
push $0
push $1
push $2
System::Call "netapi32::NetGetDCName(i0, i0, *w 0 r1) i.r2"
Dumpstate::debug
${If} 0 <> $1
${debug} "copy $1"
StrCpy $0 $1
${else}
${debug} "copy empty string"
StrCpy $0 ""
${endif}
${IfThen} $1 <> 0 ${|} System::Call "netapi32::NetApiBufferFree(ir1)" ${|}
Pop $2
Pop $1
Exch $0
FunctionEnd
编辑:感谢安德斯,这是更正的功能:
Function GetDCName
;Push the domain controler name to the stack (or an empty string if no dc)
push $0
push $1
push $2
System::Call "netapi32::NetGetDCName(i0, i0, *i 0 r1) i.r2" ;do not convert r1 to wchar, keep the pointer to free it
${If} $2 = 0
System::Call "*$1(&w${NSIS_MAX_STRLEN} .r0)" ;get the wchar from the pointer
${IfThen} $1 <> 0 ${|} System::Call "netapi32::NetApiBufferFree(ir1)" ${|} ;free the pointer
${else}
StrCpy $0 ""
${endif}
Pop $2
Pop $1
Exch $0
FunctionEnd
<>
运算符用于数字,而不是字符串。 但是,这不是您唯一的问题; *
(通常)只能与i
一起使用,而不与t
/ m
/ w
。 t
/ m
/ w
类型在C样式字符串之间来回转换,但是在这种情况下,您需要实际的内存地址,因为必须将其传递给free函数。
您需要将*i0r1
传递给NetGetDCName,然后,如果$ 2为0,则可以使用结构语法( *$1(&w${NSIS_MAX_STRLEN}.r5)
或*$1(w.r5)
)提取字符串,并最终传递未*$1(w.r5)
$ 1免费功能...
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.