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://docs.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”返回:
Cannot unbox a type object (int32) to int in method CALL-ME at C:\rakudo\share\perl6\sources \947BDAB9F96E0E5FCCB383124F9 23A6BF6F8D76B (NativeCall) line 587
非常感谢, -T
答案 0 :(得分:4)
要将指针传递到DWORD
,可以使用CArray[DWORD]
。例如,在这里我创建了一个测试库libmylib.so
,它带有一个foo()
函数,并带有DWORD *
(又名int32_t *
)自变量:
#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
答案 1 :(得分:0)
Perl6邮件列表上的JJ和Brad是正确的。对于NULL,只需将其传递零即可。我在其他地方有个嘘声。