Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to read a pointer as Struct? #644

Open
lonelywolf4git opened this issue Dec 28, 2023 · 0 comments
Open

How to read a pointer as Struct? #644

lonelywolf4git opened this issue Dec 28, 2023 · 0 comments

Comments

@lonelywolf4git
Copy link

Struct Definition

const FFI = require('ffi-napi')
const REF = require('ref-napi')
const StrucType = require('ref-struct-di')(REF)
const ALARM_ACCESS_CTL_STATUS_INFO = StrucType({
  dwSize: REF.types.int,
  nDoor: REF.types.int,
  stuTime: REF.refType(NET_TIME),
  emStatus: REF.types.int,
  szSerialNumber: ArrayType(REF.types.byte, Constants.NET_MAX_COMMON_256),
  bRealUTC: REF.types.bool,
  RealUTC: REF.refType(NET_TIME_EX)
})

The Library API:

const NetSDK = FFI.Library(NetSdkLibPath, {
  CLIENT_SetDVRMessCallBack: [REF.types.void, ['pointer', 'pointer']]
})

Callback API:

const alarmCallback = FFI.Callback(REF.types.void, [ 'pointer'], function ( pStuEvent,) {
// pStuEvent is instance of Struct "ALARM_ACCESS_CTL_STATUS_INFO"

})

Set Callback:
NetSDKLib.NetSDK.CLIENT_SetDVRMessCallBack(alarmCallback, null)

My question:
How to convert pointer "pStuEvent " to ALARM_ACCESS_CTL_STATUS_INFO instance?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant