You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Issue Description:
I'm facing an issue with ffi-napi when working with callback functions that return strings of unknown lengths from a C++ library. The problem is that I need to set csStringPointer.size to a specific value before calling the C++ function, but I don't know the exact length of the returned string in advance. Setting it too large could lead to memory waste, while setting it too small may result in string truncation.
dllLib.pollWpsResult(function (status, strPtr) {
// Issue: Unable to determine the correct size for csStringPointer.
// The length of the returned string is unknown.
const value = iconv.decode(strPtr, 'gbk');
console.log('Status:', status, 'Message:', value);
});
Expected Behavior:
I would like to find a solution or best practice for handling strings of unknown lengths when using ffi-napi. Ideally, there should be a way to dynamically allocate memory for the string in the callback without predefining the size.
Additional Information:
Operating System: [Your OS]
Node.js Version: v12.14.1
ffi-napi Version: ^2.4.5
Feel free to customize the issue template with more details specific to your project. I hope this helps, and let me know if you need further assistance.
The text was updated successfully, but these errors were encountered:
Issue Description:
I'm facing an issue with ffi-napi when working with callback functions that return strings of unknown lengths from a C++ library. The problem is that I need to set csStringPointer.size to a specific value before calling the C++ function, but I don't know the exact length of the returned string in advance. Setting it too large could lead to memory waste, while setting it too small may result in string truncation.
Code Snippet:
javascript
Copy code
const cString = ref.types.CString;
const csStringPointer = ref.refType(cString);
csStringPointer.size = 500;
const CallbackFunc = ffi.Function(ref.types.void, ['bool', csStringPointer]);
const dllLib = ffi.Library(dllPath, {
'pollWpsResult': ['void', [CallbackFunc]]
});
dllLib.pollWpsResult(function (status, strPtr) {
// Issue: Unable to determine the correct size for csStringPointer.
// The length of the returned string is unknown.
const value = iconv.decode(strPtr, 'gbk');
console.log('Status:', status, 'Message:', value);
});
Expected Behavior:
I would like to find a solution or best practice for handling strings of unknown lengths when using ffi-napi. Ideally, there should be a way to dynamically allocate memory for the string in the callback without predefining the size.
Additional Information:
Operating System: [Your OS]
Node.js Version: v12.14.1
ffi-napi Version: ^2.4.5
Feel free to customize the issue template with more details specific to your project. I hope this helps, and let me know if you need further assistance.
The text was updated successfully, but these errors were encountered: