Skip to content

Struct Pointer in callback cannot be deref() #37

@Fauny

Description

@Fauny

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!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions