gpt4 book ai didi

javascript - js-ctypes 中的 SCardListReaders 给出 0x6 错误

转载 作者:行者123 更新时间:2023-11-27 23:57:02 25 4
gpt4 key购买 nike

继续上一个问题: Error while calling SCardListReaders in js-ctypes

代码修改如下:

Cu.import('resource://gre/modules/ctypes.jsm');

var is64bit = ctypes.voidptr_t.size == 4 ? false : true;
var ifdef_UNICODE = true;

var TYPES = {
ABI: is64bit ? ctypes.default_abi : ctypes.winapi_abi,
CALLBACK_ABI: is64bit ? ctypes.default_abi : ctypes.stdcall_cabi,

CHAR: ctypes.char,
DWORD: ctypes.uint32_t,
LONG: ctypes.long,
LPCVOID: ctypes.voidptr_t,
ULONG_PTR: is64bit ? ctypes.uint64_t : ctypes.unsigned_long,
WCHAR: ctypes.jschar
};

// advanced types - based on simple types
TYPES.LPSTR = TYPES.CHAR.ptr;
TYPES.LPCSTR = TYPES.CHAR.ptr;
TYPES.LPDWORD = TYPES.DWORD.ptr;
TYPES.LPCWSTR = TYPES.WCHAR.ptr;
TYPES.LPWSTR = TYPES.WCHAR.ptr;
TYPES.SCARDCONTEXT = TYPES.ULONG_PTR;

// advanced advanced types - based on advanced types
TYPES.LPCTSTR = ifdef_UNICODE ? TYPES.LPCWSTR : TYPES.LPCSTR;
TYPES.LPTSTR = ifdef_UNICODE ? TYPES.LPWSTR : TYPES.LPSTR;
TYPES.PSCARDCONTEXT = TYPES.SCARDCONTEXT.ptr;
TYPES.LPSCARDCONTEXT = TYPES.SCARDCONTEXT.ptr;

var CONST = {
SCARD_AUTOALLOCATE: TYPES.DWORD('0xffffffff'),
SCARD_SCOPE_SYSTEM: 2,
SCARD_SCOPE_USER: 0,
SCARD_S_SUCCESS: 0
};

var cardLib = ctypes.open('Winscard');
var SCardEstablishContext = cardLib.declare('SCardEstablishContext', TYPES.ABI, TYPES.DWORD, TYPES.DWORD, TYPES.LPCVOID, TYPES.LPCVOID, TYPES.LPSCARDCONTEXT);
var SCardListReaders = cardLib.declare(ifdef_UNICODE ? 'SCardListReadersW' : 'SCardListReadersA', TYPES.ABI, TYPES.LONG, TYPES.LPSCARDCONTEXT, TYPES.LPCTSTR, TYPES.LPTSTR, TYPES.LPDWORD);
var SCardFreeMemory = cardLib.declare('SCardFreeMemory', TYPES.ABI, TYPES.LONG, TYPES.SCARDCONTEXT, TYPES.LPCVOID);
var SCardReleaseContext = cardLib.declare('SCardReleaseContext', TYPES.ABI, TYPES.LONG, TYPES.SCARDCONTEXT);

// types, consts, and functions declarations complete, now lets use it
try {
var hSC = TYPES.SCARDCONTEXT();
var rez_SCEC = SCardEstablishContext(CONST.SCARD_SCOPE_USER, null, null, hSC.address());
if (rez_SCEC.toString() != CONST.SCARD_S_SUCCESS.toString()) {
console.error('failed to establish context! error code was: ' + rez_SCEC + ' in other terms it is: 0x' + rez_SCEC.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 establish context!');
}

try {
var reader_count = TYPES.DWORD();
var reader_names = TYPES.LPTSTR.targetType(0);
var rez_SCLR = SCardListReaders(hSC.address(), null, null, reader_count.address());
console.log('rez_SCLR:', rez_SCLR, rez_SCLR.toString());
if (rez_SCLR.toString() != CONST.SCARD_S_SUCCESS.toString()) {
console.error('failed to get list of readers! error code was: ' + rez_SCLR + ' in other terms it is: 0x' + rez_SCLR.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 get list of readers!');
}
throw ('done');
var rez_free = SCardFreeMemory(hSC, reader_names);
console.log('rez_free:', rez_free, rez_free.toString());
if (rez_release.toString() != CONST.SCARD_S_SUCCESS.toString()) {
console.error('failed to free the multi-string that lists the card readers! error code was: ' + rez_release + ' in other terms it is: 0x' + rez_release.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 free the multi-string that lists the card readers!');
}
} finally {
var rez_release = SCardReleaseContext(hSC);
console.log('rez_release:', rez_release, rez_release.toString());
if (rez_release.toString() != CONST.SCARD_S_SUCCESS.toString()) {
console.error('failed to release context! error code was: ' + rez_release + ' in other terms it is: 0x' + rez_release.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 release context!');
}
}

} finally {
cardLib.close();
console.log('cardLib closed');
}

但是它也有以下错误:

“无法获取读者列表!错误代码是:6换句话说是:0x6”

异常:错误:无法获取读者列表!@Scratchpad/2:61:1WCA_evalWithDebugger@resource://gre/modules/commonjs/toolkit/loader.js -> 资源://gre/modules/devtools/server/actors/webconsole.js:1185:16WCA_onEvaluateJS@resource://gre/modules/commonjs/toolkit/loader.js -> 资源://gre/modules/devtools/server/actors/webconsole.js:797:20WCA_onEvaluateJSAsync@resource://gre/modules/commonjs/toolkit/loader.js -> 资源://gre/modules/devtools/server/actors/webconsole.js:768:20DSC_onPacket@resource://gre/modules/commonjs/toolkit/loader.js -> 资源://gre/modules/devtools/server/main.js:1456:15LocalDebuggerTransport.prototype.send/<@resource://gre/modules/devtools/dbg-client.jsm ->资源://gre/modules/devtools/transport/transport.js:561:11makeInfallible/<@resource://gre/modules/commonjs/toolkit/loader.js -> 资源://gre/modules/devtools/DevToolsUtils.js:82:14makeInfallible/<@resource://gre/modules/commonjs/toolkit/loader.js ->资源://gre/modules/devtools/DevToolsUtils.js:82:14

最佳答案

事实证明,传递给 SCardListReadershSC 是错误的。

SCardListReaders(hSC.address(),

应该是:

SCardListReaders(hSC,

关于javascript - js-ctypes 中的 SCardListReaders 给出 0x6 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32178346/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com