1
を返しましたjs-ctypeを使用してFirefoxアドオンの基本的な例を作りたいとします。ライブラリファイルが細かいコンポーネントがエラーコード0x80004002(NS_NOINTERFACE)[nsIFileURL.file]
#include "stdio.h"
extern "C"
{
__declspec(dllexport) int add(int a, int b) { return a + b; }
}
:まず、私はシンプルなCコードでの.dllファイルを作りました。私は別のプロジェクトでそれをテストしました。 私はJS-ctypesのコードでそれを読み込む:
var {Cu , Cc, Ci} = require("chrome");
Cu.import("resource://gre/modules/ctypes.jsm", null);
Cu.import("resource://gre/modules/Services.jsm");
var self = require("sdk/self");
var prompts = Cc["@mozilla.org/embedcomp/prompt-service;1"].getService(Ci.nsIPromptService);
var dataUrl = self.data.url("Js-CtypeLib.dll");
dataUrl = Services.io.newURI(dataUrl,null,null).QueryInterface(Ci.nsIFileURL).file.path;
var lib, add;
try{
console.log("Load library");
lib = ctypes.open("Js-CtypeLib.dll");
try{
declareFunc();
}
catch(e){
console.log("Error declare function");
}
}
catch(e){
console.log("Error load Library!");
}
function declareFunc(){
add = lib.declare("add", ctypes.default_abi, ctypes.int, ctypes.int, ctypes.int);
}
function test(){
var rs = add(4,2);
prompts.alert(null, "Result: ", rs);
lib.close();
}
exports.test = test;
、その後、私はindex.jsによってファイル
var buttons = require('sdk/ui/button/action');
var tabs = require("sdk/tabs");
var support = require("./support.js");
var button = buttons.ActionButton({
id: "mozilla-link",
label: "Visit Mozilla",
icon: {
"16": "./images/icon-16.png",
"32": "./images/icon-32.png",
"64": "./images/icon-64.png"
},
onClick: handleClick}
);
function handleClick(state) {
support.test();
}
最後に、CMDで、私はそれを実行support.jsを呼び出し、取得:
Component returned failure code: 0x80004002 (NS_NOINTERFACE) [nsIFileURL.file]
あなたが達成しようとしているものを/起きていることを期待されているかを説明してください。問題を再現できる完全な[mcve]を提供してください。 – Makyen
DLLを作成する必要はありません。ネイティブのプラットフォームライブラリを使用できます。これを行うには、これらの例をコピーしてコピーできます - https://developer.mozilla.org/en-US/docs/Mozilla/js-ctypes/Using_js-ctypes/Standard_OS_Libraries – Noitidart