Click to See Complete Forum and Search --> : Add event to simple object


May 12th, 1999, 04:35 AM
I have added a event to a simple object in MFC projectg by using
BEGIN_CONNECTION_PART and other macros.
(I don't want to use ATL to do this.)

//.H
BEGIN_CONNECTION_PART(CEx24bAuto, SampleConnPt)
CONNECTION_IID(xIID_ISampleSink)
END_CONNECTION_PART(SampleConnPt)

DECLARE_CONNECTION_MAP()

//.Cpp
BEGIN_CONNECTION_MAP(CEx24bAuto, CCmdTarget)
CONNECTION_PART(CEx24bAuto, IID_ISampleSink, SampleConnPt)
END_CONNECTION_MAP()

//.ODL
[
object,
uuid(532191AE-0932-11D3-889D-00A0C9C67961),
pointer_default(unique)
]
interface _CIEx24bAuto: IUnknown
{
//HRESULT OnEventFired() ;
};

[ uuid(A9515AD8-5B85-11D0-848F-00400526305B) ]
coclass Ex24bAuto
{
[default] dispinterface IEx24bAuto;
[source] interface _CIEx24bAuto;
};

When use this object in VB program as following:
Dim WithEvents xobj As Ex24b.Ex24bAuto

Private Sub Form_Load()
Set xobj = New Ex24b.Ex24bAuto '(Error 430)
End Sub
An error will occur. The error message is "Class doesn't
support Automation (Error 430)". If "WithEvents" removed,
It works correctly.

Any advice will be appreciated.

chris law
May 12th, 1999, 09:07 AM
Automation interfaces must be dispinterfaces or dual interfaces deriving from IDispatch. Late binding works through Invoke and otherwise your interface does not support invoke! You have to use only the automation types as arguments too (but you already do that, I know)

hope this helps
(PS: ATL wizards are not so bad...)

chrislaw

David L Hill
May 12th, 1999, 09:54 AM
Visual Basic (at least the later versions) will support custom interfaces but require automation compatible parameters. If you add the oleautomation interface attribute, it should allow you to use the event in VB. If you go ahead and make it a dual interface the oleautomation attribute is implied and not need.

May 12th, 1999, 08:07 PM
Every dispinterface is implicitly OLE Automation-compatible,
So all interfaces in this project are Automation-compatible.
Now I had removd all metohds and properties, But It was not
work yet. What' wrong with it? Can anybody paste a sample here?

Thanks for all helps.

David L Hill
May 13th, 1999, 03:42 PM
It looked to me like your sink interface was deriving from IUnknown. If you use the OLE/COM Object Viewer, is the interface in your type library listed as a dispinterface or as an interface with oleautomation attribute (if is has the dual attribute oleautomation is automatically added in the type lib). When I have used VB, I have had problems if my interface in the type library did not specify oleautomation even if the parameters were automation compatible.