Make sure you have a dual interface (or else a private COM-only interface
you can QI for). One such method needs to be declared with hidden,
restricted and local (preferably named with a leading _). The result of this
is a long to keep it from being marshaled and this is then cast into your
native class pointer. My root interface follows:
[
uuid(...),
hidden, dual, oleautomation, nonextensible
]
interface IFooRoot : IDispatch
{
// Properties
[id(DISPID_THIS), propget, hidden, restricted, local]
HRESULT _This([out, retval] long* ppThis); // OK, so I lied -- sue me.
[id(DISPID_USERDATA), propget, helpstring("Stores arbitrary data for use by
the caller.")]
HRESULT UserData([out, retval] VARIANT* UserData);
[id(DISPID_USERDATA), propput, helpstring("Stores arbitrary data for use by
the caller.")]
HRESULT UserData([in] VARIANT UserData);
[id(DISPID_USERDATA), propputref, helpstring("Stores arbitrary data for use
by the caller.")]
HRESULT UserData([in] VARIANT* UserData);
// Methods
[id(DISPID_ISSAMEAS), helpstring("Returns true if passed object represents
the same object as this one.")]
HRESULT IsSameObject([in] IDispatch* OtherObject, [out, retval]
VARIANT_BOOL* pResult);
};
Does this help?
Ciao,
Dee
-----Original Message-----
From: BeginThread.com MSVC List [mailto:[EMAIL PROTECTED]]On Behalf
Of Jason Teagle
Sent: Thursday, September 11, 2003 9:41 AM
To: MSVC At BeginThread
Subject: [msvc] Automation, IDispatch, Class Explosing The Interface
I'm writing an OCX or two in VC (6, not .NET).
I'm primarily using the OCXs as controls in a VB application. Used
individually, no problems whatsoever (I might even venture to say I'm
getting proficient at creating OCXs!).
I want one OCX to be able to use the other (act as a layer on top). I want
the VB app to be able to tell one control about the other, so that
internally the first control can call the second's methods natively, if
possible.
I can pass "the control" into a method in the other by wrapping it in a
variant. What comes through in the VC code is a VARIANT of type VT_DISPATCH.
Thus, I can get an IDispatch out of it easily.
Now comes the crunch: I'd like, ideally, to be able to get hold of the
instance of the class that exposes that interface, my control class, so that
I can call its methods directly. But so far, all I can find is that I can
try and call those functions using IDispatch::Invoke() or use things like
CreateStdDispatch() and DispatchInvoke() (all of which I barely understand).
Is there any way I can use something like a CoGetXXX() call or something to
get access to the COleControl object (on which the OCX is based) from that
IDispatch?
If not, what would people recommend would be the best way to get OCX 1 to
use that IDispatch from OCX 2 to call OCX 2 methods?
Any help or pointers (groan) would be appreciated.
--
Jason Teagle
[EMAIL PROTECTED]
