Convert IDispatch* to a string?

Posted by Rob on Stack Overflow See other posts from Stack Overflow or by Rob
Published on 2010-02-24T18:24:08Z Indexed on 2010/03/15 6:09 UTC
Read the original article Hit count: 364

Filed under:
|
|

I am converting an old VB COM object (which I didn't write) to C++ using ATL. One of the methods, according to the IDL, takes an IDispatch* as a parameter and the documentation and samples for this method claim that you can pass either a string (which is the progid of an object that will be created and used by the control) or an IDispatch* to an object that has already been created. How on earth do I implement this in ATL?

For example, the IDL:

[id(1)] HRESULT Test(IDispatch* obj);

The samples (which are all JScript):

obj.Test("foo.bar");

or

var someObject = new ActiveXObject("foo.bar");
obj.Test(someObject);

To make matters even more bizarre the actual VB code that implements this method actually declares the 'obj' parameter as a string! However, it all seems to work.

Can you even pass a string to a COM method that takes an IDispatch*? If so, can I determine that the IDispatch* is actually a string in my C++ ATL code? Even better, if it's an IDispatch that implements a specific interface I will want to call methods on it, or instantiate an object if it's a string.

Any ideas welcome!

© Stack Overflow or respective owner

Related posts about atl

Related posts about com