Convert IDispatch* to a string?
- by Rob
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!