This here shows how to use different functions with jsctypes. It may not be specific to your stuff above, if this doesn't help you out let me know and I'll take a look at your specific case.
const {Cc, Ci, Cu} = require('chrome');
Cu.import("resource://gre/modules/ctypes.jsm");
/*start getcursorpos*/
var lib = ctypes.open("user32.dll");
/*foreground window stuff*/
var FindWindowA = lib.declare('FindWindowA', ctypes.winapi_abi, ctypes.uint32_t, ctypes.jschar.ptr, ctypes.jschar.ptr)
var GetForegroundWindow = lib.declare('GetForegroundWindow', ctypes.winapi_abi, ctypes.uint32_t)
function doFindWindow() {
var wm = Cc['@mozilla.org/appshell/window-mediator;1'].getService(Ci.nsIWindowMediator);
var title = wm.getMostRecentWindow('navigator:browser').gBrowser.contentDocument.title;
Cu.reportError('title=' + title)
var ret = FindWindowA('', title + ' - Mozilla Firefox');
//var ret = GetForegroundWindow();
Cu.reportError(ret);
}
/*end foreground window stuff*/
/* Declare the signature of the function we are going to call */
const struct_lpPoint = new ctypes.StructType("lpPoint",
[ { "x": ctypes.int },
{ "y": ctypes.int } ]);
var GetCursorPos = lib.declare('GetCursorPos', ctypes.winapi_abi, ctypes.bool, struct_lpPoint.ptr);
function doGetCursorPos() {
var point = new struct_lpPoint;
var ret = GetCursorPos(point.address());
Cu.reportError(ret);
Cu.reportError(point);
}
/*end getcursorpos*/
/*start setcursorpos*/
//var lib = ctypes.open("user32.dll"); //already called on line 4
var SetCursorPos = lib.declare('SetCursorPos', ctypes.winapi_abi, ctypes.bool, ctypes.int, ctypes.int)
function doSetCursorPos() {
var ret = SetCursorPos(10, 10);
}
/*end setcursorpos*/
/*start mouse_event*/
//used to click
//const DWORD = ctypes.uint32_t; //this just shows you that DWORD == ctypes.uint32_t
var mouse_event = lib.declare('mouse_event', ctypes.winapi_abi, ctypes.void_t, ctypes.uint32_t, ctypes.uint32_t, ctypes.uint32_t, ctypes.uint32_t, ctypes.uintptr_t);
const MOUSEEVENTF_LEFTDOWN = 2;
const MOUSEEVENTF_LEFTUP = 4;
function domouse_event() {
var ret = mouse_event(MOUSEEVENTF_LEFTDOWN, 0, 0, 0, 0);
var ret = mouse_event(MOUSEEVENTF_LEFTUP, 0, 0, 0, 0);
}
/*end mouse_event*/
/*start MessageBoxW*/
//var lib = ctypes.open("user32.dll"); //already called on line 4
var MessageBoxW = lib.declare('MessageBoxW', ctypes.winapi_abi, ctypes.int32_t, ctypes.int32_t, ctypes.jschar.ptr, ctypes.jschar.ptr, ctypes.int32_t);
var MB_OK = 0;
function doMessageBoxW() {
var ret = MessageBoxW(0, "Hello world", "title", MB_OK);
}
/*end MessageBoxW*/
exports.main = function (options, callbacks) {
};
exports.onUnload = function (reason) {
lib.close();
}
var { Hotkey } = require("hotkeys");
var showHotKey = Hotkey({
combo: "alt-w",
onPress: function() {
/*setcursor stuff*/
//doSetCursorPos();
//domouse_event();
/*setcursor stuff*/
/*foreground stuff*/
doFindWindow();
/*foreground stuff*/
}
});
Other jsctype topics on stackoverflow I found useful:
* Javascript String to C++ char pointer -LPSTR buffer in JSCTypes
* FF addon: How to declare C function fgets in javascript