Looks like COM object is created, but JScript fails to get a reference

Posted by damix911 on Stack Overflow See other posts from Stack Overflow or by damix911
Published on 2013-07-01T10:19:41Z Indexed on 2013/07/01 10:21 UTC
Read the original article Hit count: 298

Filed under:
|
|

I'm using the following code to create a COM component that I have developed and registered.

var mycom = new ActiveXObject("Mirabilis.ComponentServices.1");

mycom.SetFirstNumber(5);
mycom.SetSecondNumber(3);

The first line runs fine, while if I alter the ProgID (that is, the string passed to ActiveXObject) I get the message Automation server can't create object. This suggests that at least the basics of the registration mechanism are working properly.

I integrated some logging calls into the DLL. When I run the script I get the proof into the log file that both this call to QueryInterface:

STDAPI DllGetClassObject(
    const CLSID &clsid,
    const IID &iid,
    void **ppv)
{
    ...
        CAddFactory *pAddFact = new CAddFactory;
        ...
        HRESULT hr = pAddFact->QueryInterface(iid, ppv);

        if (hr == S_OK)
            writeToLogFile("Class QueryInterface returned S_OK");
        else
            writeToLogFile("Class QueryInterface failed");

        return hr;
    ...
}

and this one:

HRESULT __stdcall CAddFactory::CreateInstance(
    IUnknown *pUnknownOuter,
    const IID &iid,
    void **ppv)
{
    ...
        CAddObj *pObject = new CAddObj;
        ...
        HRESULT hr = pObject->QueryInterface(iid, ppv);

        if (hr == S_OK)
            writeToLogFile("Object QueryInterface returned S_OK");
        else
            writeToLogFile("Object QueryInterface failed");

        return hr;
    ...
}

return S_OK. However, when JScript gets to line 3 of the script, I get the following error message:

'mycom' is null or not an object

Why is this happening? It looks like JScript should be able to obtain a reference.

Some attempts I made

  • I tried to return S_FALSE from DllCanUnloadNow to be sure that the DLL will not be unloaded, just in case, but with no luck.

© Stack Overflow or respective owner

Related posts about dll

Related posts about com