Функция SCardTransmit определена в https://msdn.microsoft.com/en-us/library/windows/desktop/aa379804%28v=vs.85%29.aspx
Я хочу объявить и использовать эту функцию, у меня есть проблемы с определением некоторых аргументов в js-ctypes (особенно в приведении типов):
Как определить, инициализировать и использовать их?
Вот мой код:
//-----------------define types----------------------
Cu.import('resource://gre/modules/ctypes.jsm');
var TYPES = {
ABI: is64bit ? ctypes.default_abi : ctypes.winapi_abi,
DWORD: ctypes.uint32_t,
LONG: ctypes.long,
BYTE: ctypes.unsigned_char //ctypes.uint8_t
};
TYPES.LPDWORD = TYPES.DWORD.ptr;
TYPES.SCARDCONTEXT = TYPES.ULONG_PTR;
TYPES.SCARDHANDLE = TYPES.ULONG_PTR;
TYPES.LPBYTE = TYPES.BYTE.ptr;
var CONST = {
SCARD_PROTOCOL_T0: 0x00000000,
SCARD_PROTOCOL_T1: 0x00000001
}
const SCARD_IO_REQUEST = new ctypes.StructType("myStruct" ,
[{"dwProtocol": TYPES.DWORD},
{"cbPciLength": TYPES.DWORD}]);
//------------------declaration-------------------------
var SCardTransmit = cardLib.declare('SCardTransmit', TYPES.ABI, TYPES.LONG, TYPES.SCARDHANDLE, SCARD_IO_REQUEST.ptr, TYPES.LPBYTE, TYPES.DWORD, SCARD_IO_REQUEST.ptr, TYPES.LPBYTE, TYPES.LPDWORD);
//------------------initializing---------------------
var _SCARD_IO_REQUEST = new SCARD_IO_REQUEST;
_SCARD_IO_REQUEST.dwProtocol = CONST.SCARD_PROTOCOL_T0|CONST.SCARD_PROTOCOL_T1;
_SCARD_IO_REQUEST.cbPciLength = _SCARD_IO_REQUEST.dwProtocol.toString().length;
var command = ctypes.char.array(42)("00a4040010a0000000183003010000000000000000");
var commandLength = command.toString().length;
var response = TYPES.LPBYTE;
var responseLength = TYPES.LPDWORD;
//----------------using-------------------------
var rez_SCT = SCardTransmit(cardHandle, _SCARD_IO_REQUEST, command, commandLength, null, response, responseLength.address());
if(rez_SCT.toString() != CONST.SCARD_S_SUCCESS.toString())
{
console.error('cannot begin transaction, error code was: ' + rez_SCT + ' in other terms it is: 0x' + rez_SCT.toString(16) + ' you can look up this error value here: https://msdn.microsoft.com/en-us/library/windows/desktop/aa374738%28v=vs.85%29.aspx#smart_card_return_values');
throw new Error('failed to begin transactio!');
}
Задача ещё не решена.