views:

81

answers:

1

I have written a COM object using C++.

Creating the object and connecting to its events works fine if I do them both at the same time (Javascript):

var obj = WScript.CreateObject("SomeCOMClass.Object", "event_");

However the following generates this error (msdn): http://msdn.microsoft.com/en-us/library/a7tya2wc(VS.85).aspx.

var obj = WScript.CreateObject("SomeCOMClass.Object");
WScript.ConnectObject(obj, "event_");

The error description page does not describe why I cannot connect to already created objects. I would like to be able to connect to created objects because I plan on returning objects from various C++ COM functions.

+1  A: 

I just found an old blog post by Eric Lippert describing this: http://blogs.msdn.com/ericlippert/archive/2005/02/15/373330.aspx

Essentially, he says you need your objects to implement IProvideClassInfo or IProvideMultipleClassInfo in order for WScript to harvest type info about the outgoing (callback) interfaces, so it can set up a matching handler.

Kim Gräsman