2

I am buiding a simple XPCOM component. but firefox crashes everytime when I am trying to call a method of this xpcom component.

the file hierarchy is below:

HelloXpcom.xpi
---chrome.manifest
---install.rdf
---chrome
------content
---------sample.xul
---components
------HelloXpcom.dll
------nsISample.xpt

chrome.manifest snippet

content     sample    chrome/content/
interfaces components/nsISample.xpt
binary-component components/HelloXpcom.dll

overlay chrome://browser/content/browser.xul chrome://sample/content/sample.xul

my interface idl:

#include "nsISupports.idl"
[scriptable, uuid(F7F48977-382E-461B-B04A-44567EE6D45A)]
interface nsISample : nsISupports
{
    attribute string value;
    void writeValue(in string aPrefix);
    void poke(in string aValue);
};

use xpidl.exe to generate npISample.h and npISample.xpt. and all the implementation methods are almost nothing, just do some simple thing.

sample.xul

<?xml version="1.0"?>
<overlay id="sample" 
         xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
<statusbar id="status-bar">
<script>
function DoXPCOM()
{
    try {
        alert("1");
        var sample = Components.classes["@baofeng/sample;1"].createInstance();
        alert("2");
        sample = sample.QueryInterface(Components.interfaces.nsISample);
        alert("3");
        dump("sample = " + sample + "\n");
    }
    catch(err) {
        alert(err);
        return;
    }

    var res = sample.SetValue("123");
    var str = "";
    obj.GetValue(str);
    alert(str);
}
</script>
<button label="xpcom" oncommand="DoXPCOM();"/>
</statusbar>
</overlay>

"alert("1");" is executed, It crashes at "Components.classes["@baofeng/sample;1"].createInstance();" the contact ID "@baofeng/sample;1" is recognized by firefox, if not, there should be some info like "@baofeng/sample;1" undefined pops out. So the createInstance() method is the point.
can someone help me out of this?

Quark
  • 55
  • 1
  • 7

0 Answers0