「http://nerdlife.net/building-ac-xpcom-component-in-windows/」にある xpcom チュートリアルを組み込んで、wxWebConnectテスト アプリケーションで実験を行っています。
必要に応じて MyComponent クラスを testapp.exe と一緒に (別の dll としてではなく) コンパイルします。MyApp::OnInit には次の行があります。
ns_smartptr<nsIComponentRegistrar> comp_reg;
res = NS_GetComponentRegistrar(&comp_reg.p);
if (NS_FAILED(res))
return false;
ns_smartptr<nsIFactory> prompt_factory;
CreateMyComponentFactory(&prompt_factory.p);
nsCID prompt_cid = MYCOMPONENT_CID;
res = comp_reg->RegisterFactory(prompt_cid,
"MyComponent",
"@mozilla.org/mycomp;1",
prompt_factory);
これらの行は GeckoEngine::Init() からコピーされ、同じメカニズムを使用して PromptService などを登録します。コードは適切にコンパイルされ、testapp.exe は期待どおりに実行されます。
以下のようにjavascriptテストを入れます:
try {
netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
const cid = "@mozilla.org/mycomp;1";
obj = Components.classes[cid].createInstance();
alert(typeof obj);
// bind the instance we just created to our interface
alert(Components.interfaces.nsIMyComponent);
obj = obj.QueryInterface(Components.interfaces.nsIMyComponent);
} catch (err) {
alert(err);
return;
}
次の例外が発生します: JavaScript 引数 arg 0 [nsISupport.QueryInterface] を変換できませんでした
最初のアラートには「オブジェクト」と表示されているため、この行は
Components.classes[cid].createInstance()
作成されたインスタンスを返しています。
2 番目のアラートは「未定義」であるため、インターフェイス nsIMyComponent は XULRunner によって認識されません。wxWebConnect 環境で nsIMyComponent インターフェイスを動的に登録するには?
どうも