CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 5 of 5
  1. #1
    Guest

    Add event to simple object


    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.




  2. #2
    Join Date
    May 1999
    Posts
    69

    Re: Add event to simple object

    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

  3. #3
    Join Date
    May 1999
    Location
    Indiana
    Posts
    21

    Re: Add event to simple object

    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.


  4. #4
    Guest

    Re: Add event to simple object


    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.







  5. #5
    Join Date
    May 1999
    Location
    Indiana
    Posts
    21

    Re: Add event to simple object

    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.


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured