我正在编写一个Firefox扩展,它将获取当前浏览器的句柄并将其写入sqlite数据库。我的整个代码是:Firefox扩展中的SQLite3错误
Components.utils.import("resource://gre/modules/Services.jsm");
Components.utils.import("resource://gre/modules/FileUtils.jsm");
let file = FileUtils.getFile("ProfD", ["testing.sqlite"]);
let dbConn = Services.storage.openDatabase(file);
var browserWindow = Services.wm.getMostRecentWindow('navigator:browser');
if (!browserWindow) {
throw new Error('No browser window found');
}
var baseWindow = browserWindow.QueryInterface(Ci.nsIInterfaceRequestor)
.getInterface(Ci.nsIWebNavigation)
.QueryInterface(Ci.nsIDocShellTreeItem)
.treeOwner
.QueryInterface(Ci.nsIInterfaceRequestor)
.getInterface(Ci.nsIBaseWindow);
var hwndString = baseWindow.nativeHandle;
Components.utils.import('resource://gre/modules/ctypes.jsm');
var user32 = ctypes.open('user32.dll');
/* http://msdn.microsoft.com/en-us/library/ms633539%28v=vs.85%29.aspx
* BOOL WINAPI SetForegroundWindow(
* __in_ HWND hWnd
*);
*/
var SetForegroundWindow = user32.declare('SetForegroundWindow', ctypes.winapi_abi,
ctypes.bool, // return BOOL
ctypes.voidptr_t // HWND
);
var hwnd
hwnd = ctypes.voidptr_t(ctypes.UInt64(hwndString));
var rez_SetForegroundWindow = SetForegroundWindow(hwnd);
console.log('hwnd: ', hwnd.toString());
dbConn.createStatement("INSERT INTO tblHandles(handle) VALUES("+ hwnd +")");
//dbConn.executeSimpleSQL("INSERT INTO tblHandles(handle) VALUES("+ hwnd+")");
user32.close();
我收到错误:
NS_ERROR_FAILURE: Component returned failure code: 0x80004005 (NS_ERROR_FAILURE) [mozIStorageConnection.createStatement]
在该行:
dbConn.createStatement("INSERT INTO tblHandles(handle) VALUES("+ hwnd +")");
双方的createStatement和executeSimpleSQL抛出了同样的错误,我不知道为什么。
这工作完美切换到hwndString。 – Resistance
酷@TravisStauffer,但确保当你从数据库中读取,以确保你做'ctypes.voidptr_t(ctypes.UInt64'从表 – Noitidart
读取值我使用ac#程序来读取存储的句柄,所以我转换它回到那里十六进制它现在工作完美 – Resistance