https://docs.perl6.org/language/nativecall
"As you may have predicted by now, a NULL pointer
is represented by the type object of the struct type."
https://learn.microsoft.com/en-us/windows/win32/api/winreg/nf-winreg-regqueryvalueexw
C++
LSTATUS RegQueryValueExW(
HKEY hKey,
LPCWSTR lpValueName,
LPDWORD lpReserved,
LPDWORD lpType,
LPBYTE lpData,
LPDWORD lpcbData
);
lpReserved
This parameter is reserved and must be NULL.
对于“本机”,我如何满足“空”的要求?
constant WCHAR := uint16;
constant DWORD := int32;
sub RegQueryValueExW( DWORD, WCHARS, DWORD, DWORD, DWORD is rw, DWORD is rw ) is native("Kernel32.dll") returns DWORD { * };
$RtnCode = RegQueryValueExW( $Handle, $lpValueName, int32, REG_DWORD, $lpData, $lpcbData );
"int32“返回:
不能在C:\rakudo\perl6\source \947BDAB9F96E0E5FCCB383124F9 23A6BF6F8D76B (NativeCall)行587行中将类型对象(int32)解压缩为int
非常感谢,-T
发布于 2019-12-29 09:33:49
JJ和Perl6邮件列表上的布拉德都是正确的。如果为空,只需将其传递为零。我在别的地方喝了酒。
发布于 2019-12-29 01:18:30
要传递指向DWORD
的指针,可以使用CArray[DWORD]
。例如,在这里,我创建了一个测试库libmylib.so
,其中包含一个带有DWORD *
(又名int32_t *
)参数的foo()
函数:
#include <stdio.h>
#include <stdint.h>
void foo (int32_t *bar) {
if ( bar == NULL ) {
printf( "Got NULL pointer\n" );
}
else {
printf("Got bar: %d\n", bar[0]);
}
}
然后使用以下方法测试这个库的Raku接口:
use v6;
use NativeCall;
constant DWORD := int32;
sub foo(CArray[DWORD]) is native("./libmylib.so") { * };
my @bar := CArray[DWORD].new;
@bar[0] = 1;
foo(@bar);
foo(CArray[DWORD]); # <-- Use a type object to pass a NULL pointer
输出
Got bar: 1
Got NULL pointer
https://stackoverflow.com/questions/59500796
复制相似问题