Search code examples
javascriptdllfirefox-addonxuljsctypes

How to distribute a native Windows DLL to use with js-ctypes inside a XUL Firefox extension


I have a Firefox XUL extension which makes use of a native Windows DLL using js-ctypes.

Which is the recommended way to distribute this DLL file?

I have set up a development environment just like the one that is described in the XUL School Tutorial, but I am not sure which modifications should I make to the directory structure and the corresponding build files (Makefile, manifest, etc) to have my DLL included into the XPI file, and then available to js-ctypes when the client uses the extension.

Any pointers will be greatly appreciated.

Regards!


Solution

  • Usually you would simply zip the DLL into your XPI with the rest of your stuff and use em:unpack=true, or else you won't be able to load your DLL.

    Then you can use e.g. the Add-on Manager to find out where the DLL is actually installed on a user system and load it with js-ctypes.

    Components.utils.import("resource://gre/modules/AddonManager.jsm");
    
    AddonManager.getAddonByID(YOUR_ADDON_ID, function(addon) {
        //var uri = addon.getResourceURI(YOUR_RELATIVE_PATH_TO_THE_DLL);
        var uri = addon.getResourceURI("install.rdf");
        console.log("uri", uri.spec);
        if (uri instanceof Components.interfaces.nsIFileURL) {
            var file = uri.file;
            console.log("path", file.path);
        }
    });
    

    BTW: This stuff still works when the add-on is installed via a proxy file for development purposes.