user3812797
user3812797

Reputation: 41

FF addon, js ctypes: couldn't open library (dll)

I'm building a firefox addon that uses js-ctypes to load a C library. This library is included in the addon itself (i.e. inside the "data" directory). It works fine in Linux and OSX, where I'm loading a .so and .dylib file, respectively. But when I try to load the .dll in windows, it fails with

Message: Error: couldn't open library c:\users...\appdata\local\temp...\customlib.dll

When I follow the path, the customlib.dll file is indeed where ctypes is looking. When I open it with dllexp I see all the symbols, so I think the .dll itself is fine.

I'm not sure what info to provide. This is how I'm trying to open the lib with ctypes

var {Cc, Cu, Ci} = require("chrome");
Cu.import("resource://gre/modules/Services.jsm");
var {ctypes} = Cu.import("resource://gre/modules/ctypes.jsm", null);

function resolveToFile(uri) {
    var ResProtocolHandler = Services.io.getProtocolHandler("resource")
        .QueryInterface(Ci.nsIResProtocolHandler);
    var ChromeRegistry = Cc["@mozilla.org/chrome/chrome-registry;1"]
        .getService(Ci.nsIChromeRegistry);
    switch (uri.scheme) {
        case "chrome":
            return resolveToFile(ChromeRegistry.convertChromeURL(uri));
        case "resource":
            return resolveToFile(Services.io.newURI(ResProtocolHandler.resolveURI(uri), null, null));
        case "file":
            return uri.QueryInterface(Ci.nsIFileURL).file;
        default:
            throw new Error("Cannot resolve");
    }
}

function getLibName(){
    return "customlib.dll";
}

var loc = resolveToFile(Services.io.newURI(self.data.url(getLibName()),null,null));
var lib = ctypes.open(loc.path);

I got the resolveToFile() from here how to load dll from SDK addon data folder?, and it works like a charm in the sense that it finds the right path to the libs included in the addon. But again, it won't open in Windows.

Upvotes: 1

Views: 601

Answers (1)

Noitidart
Noitidart

Reputation: 37238

Instead of var {ctypes} = Cu.import("resource://gre/modules/ctypes.jsm", null); do just Cu.import("resource://gre/modules/ctypes.jsm");

is this code running from a ChromeWorker?

also do this:

var self = require("sdk/self");
ctypes.open(self.data.url('customlib.dll'));

Upvotes: 1

Related Questions