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
hello, everyone, I want to call C++ code in JavasSript. After I called the initialize funtion, the callback funtion is a parameter of the initilialize funtion, the callback fution will be registered, and after some operations, the C++ code will call the callback funtion the definition is below:
C++ Struct definition:
`#define MAX_EXTRA_MESSAGE_LEN 1024
struct Message {
unsigned int verison;
int sessionId;
unsigned int messageId;
unsigned int errorCode;
char extraMessage[MAX_EXTRA_MESSAGE_LEN];
union {
DistributedBundle bundle;
struct {
unsigned int dataSize;
void data;
};
};
};
int Honor_Distributed_Initialize(int appId, const char* processName, int nameLen, DISTRIBUTED_PROC lpfnProc)
int Honor_Distributed_Initialize(int appId,const char* processName,int nameLen,DISTRIBUTED_PROC lpfnProc)
`
The Question is: when the callback is called, I can not get data from messageInfo, and the logger is "version undefined, sessionID undefine...", so how to code the callback funtion? thanks.
The text was updated successfully, but these errors were encountered:
hello, everyone, I want to call C++ code in JavasSript. After I called the initialize funtion, the callback funtion is a parameter of the initilialize funtion, the callback fution will be registered, and after some operations, the C++ code will call the callback funtion the definition is below:
C++ Struct definition:
`#define MAX_EXTRA_MESSAGE_LEN 1024
struct Message {
unsigned int verison;
int sessionId;
unsigned int messageId;
unsigned int errorCode;
char extraMessage[MAX_EXTRA_MESSAGE_LEN];
union {
DistributedBundle bundle;
struct {
unsigned int dataSize;
void data;
};
};
};
int Honor_Distributed_Initialize(int appId, const char* processName, int nameLen, DISTRIBUTED_PROC lpfnProc)
int Honor_Distributed_Initialize(int appId,const char* processName,int nameLen,DISTRIBUTED_PROC lpfnProc)
`
callback definition:
typedef void (* DISTRIBUTED_PROC)(const Message* msg);
my code is below:
`
const distributedBundle = ref.types.void
const distributedBundlePtr = ref.refType(distributedBundle)
const distributedMessage = Struct({
'version': ref.types.uint,
'sessionId': ref.types.int,
'messageId': ref.types.uint,
'errorCode': ref.types.uint,
'extraMesssage': refArray(ref.types.char, 1024),
// 'bundleData': messageUnion,
'bundle': distributedBundlePtr,
})
const distributedMessagePtr = ref.refType(distributedMessage)
distributedServiceLibrary = ffi.Library(resolvePath('build-win/dll/DistributedKit.dll'), {
'Honor_Distributed_Initialize': ['int', ['int', 'string', 'int', 'pointer']],
......
const callback = ffi.Callback('void', [distributedMessagePtr], function(messageInfo: any) {
Logger.info('[distributed service]: ffi.Callback called')
messageInfo.type = distributedMessagePtr
// const msg = ref.alloc(distributedMessagePtr, messageInfo)
Logger.info(
[distributed service]: version ${messageInfo.deref().version}
)Logger.info(
[distributed service]: sessionID ${messageInfo.deref().sessionId}
)Logger.info(
[distributed service]: messageId ${messageInfo.deref().messageId}
)I registered the callback below:
const initServiceResult = distributedServiceLibrary.Honor_Distributed_Initialize(appid, packageName, packageLen, callback)`The Question is: when the callback is called, I can not get data from messageInfo, and the logger is "version undefined, sessionID undefine...", so how to code the callback funtion? thanks.
The text was updated successfully, but these errors were encountered: