这是部分 .h
头文件
#ifndef _GENERIC_GB_API_H_
#define _GENERIC_GB_API_H_
#ifdef WIN32
#ifdef DLL_GBSDK
#define GBAPI _declspec(dllexport)
#else
#define GBAPI _declspec(dllimport)
#endif
#else
#define GBAPI
#endif
typedef unsigned long long UINT64;
typedef long long INT64;
#ifdef __cplusplus
extern "C" {
#endif
typedef struct _LogInfo
{
char severip[16]; //内存占16个字节
int severport;
char severid[24];
char localip[16];
int localport;
char username[24];
char password[64];
int keepalive;
int timeout;
int expires;
}LogInfo;
typedef void (*Callback_Offline)( void *userdata );
void GBAPI NP_GB_Init();
int GBAPI NP_GB_Login( void* userdata, LogInfo &info, Callback_Offline callback );
int GBAPI NP_GB_OpenToDecoder( char* id, char* decoder );
#ifdef __cplusplus
}
#endif
#endif
我想问的是如何调 NP_GB_Login
函数呢?写了一部分代码,下面不知道该如何写了,这个结构体定义正确吗?
var ffi = require('ffi');
var ref = require('ref');
var Struct = require('ref-struct');
//var hWnd = new Buffer(8);
var int64_t = ref.types.int64;
var voidptr = ref.refType(ref.types.void);
var intptr = ref.refType(ref.types.int);
var uint8_ptr = ref.refType(ref.types.uint8);
/** 登录信息
*
*/
var _LogInfo = Struct({
'severip': "string",
'severport': "int32",
"severid": "string",
"localip": "string",
"localport": "int32",
"username": "string",
"password": "string",
"keepalive": "int32",
"timeout": "int32",
"expires": "int32"
});
//byte[24];
var _LogInfoPtr = ref.refType(_LogInfo);
var Callback_Offline=ffi.callback("void",["void"],function(userdata){
});
var SDKHandle = ffi.Library('./sdk.dll', {
'NP_GB_Init': ['void', ["void"]],
'NP_GB_Cleanup': ['void', ["void"]],
'NP_GB_Login': ['int', ["void",_LogInfoPtr,"pointer"]],
'NP_GB_Logout': ['void', ["void"]]
});
运行不正常。哪里不正确呢