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.