Closed btsimonh closed 1 week ago
void* is not null pointer but a generic pointer.
Create a pointer with specify type by ffi-rs.createPointer
Check a pointer whether is null pointer refer https://github.com/zhangyuang/node-ffi-rs/issues/64#issuecomment-2260414751
thankyou for the quick response. It would be really useful to have a function like ref.isNull(pntrvar) inside ffi-rs. I don't want to write a new DLL and .so just to get this feature :(. Also, to have ffi-rs.createPointer(null) create a null pointer?
Support ffi-rs.isNullPointer in 1.0.97
Get a null pointer from return value or createPointer
const nullPointer = load({
library: "libsum",
funcName: "returnNullPointer",
retType: DataType.External,
paramsType: [],
paramsValue: [],
})
equal(isNullPointer(nullPointer), true)
const rsNullPointer = createPointer({
paramsType: [DataType.Void],
paramsValue: [undefined]
})
equal(isNullPointer(unwrapPointer(rsNullPointer)[0]), true)
logGreen('test null pointer success')
CreatePointer will create a pointer point to specify data type which is null pointer in this scene.So we should use unwrapPointer to get the wrapped pointer in the package.
If you get a null pointer type by ffi method return value, use it directly.
If you create a null pointer type by createPointer type and use it to call another ffi function. Use unwrapPointer for it,
Current ffi-rs version
Print current Node.js info with the following code
"version": "1.0.96",
$ ls node_modules/@yuuang node_modules\@yuuang\ffi-rs-win32-x64-msvc + i164
Current Node.js arch
22.10.0
Print current Node.js info with the following code
$ node -e "console.log(process.arch, process.platform)" x64 win32
Descibe your problem in detail
How do I create a null pointer? Howe do I compare a pointer to null?
What's your expect result
I expect to be able to understand how to pass null pointers to API functions, and to detect null pointers.
The reproduction repo address
Full Example:
Here we are getting certificates from the windows certificate store. The CertOpenSystemStoreA(hProv, Storename) call's first parameter should be a null pointer. I have forced this with an I64 = 0???
context = CertEnumCertificatesInStore( handle, context ) must be passed context as null first call, then the returned context in the next, until it returns zero. I have spoofed this for the first call to use I64, and External in subsequent calls.
But I don't know how to test if context becomes null...
I'm finding it very difficult to understand how to create a null pointer, or check if a pointer is null?