fastcall icon indicating copy to clipboard operation
fastcall copied to clipboard

Struct Pointer in callback cannot be deref()

Open Fauny opened this issue 6 years ago • 2 comments

as title says, this works in ffi mode

const MyStruct = RefStruct({a: 'int', b:'int'});
const PtrMyStruct = ref.refType(MyStruct);
const MyLib = ffi.Library('mylib.dll',{
   setCB:['void', ['pointer']],
  //...other things
});

let myCB = ffi.Callback('void', [PtrMyStruct ]], (ptrInCallback) => {
  let struct = prtInCallback.deref();
  // now, I got a js  object, everything is ok
));

MyLib.setCB(myCB);

here is my fastcall codes

const lib = fastcall.Library('mylib.dll')
lib.struct( 'struct MyStruct{int a; int b}'
lib.declare( 'void (*CB)( MyStruct * ptrInCallback)'
lib.function('void setCB(CB)')

lib.interface.setCB((ptrInCallback)=>{
    let struct = prtInCallback.deref();
   //Error!!!,  value of ptrInCallback is uint8array[0]
})

Thank you!

Fauny avatar Jul 19 '18 04:07 Fauny

Having this issue @Fauny did you ever find a resolution?

Zayelion avatar May 31 '19 02:05 Zayelion

Ended up reverting back to FFI due to this issue.

Zayelion avatar Jul 08 '19 15:07 Zayelion