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

Thread: Returning interface pointer

  1. #1
    Join Date
    Nov 2003
    Posts
    2,185

    Returning interface pointer

    Hi all,

    I want to return a pointer to a COM interface.
    I have a COM interface ICollection. This interface has a function GetConnection. It should return a pointer to a IConnection object.

    Now I have this function:
    Code:
    CCollection::GetConnection(short index, IConnection * pConnection)
    {
        pConnection = m_arrConnections[index];
    
        return S_OK;
    }
    However, my compiler says:
    MIDL2284 : [out] interface pointers must use double indirection
    Since the altered value is the pointer to the interface, there must be another level of indirection above it to allow it to be returned.
    So, I think now I have to use ** instead of *. But then I get other compile errors.

    What is the right way to return an interface of a COM object?

    Thanks!

  2. #2
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Wallisellen (ZH), Switzerland
    Posts
    17,472

    Re: Returning interface pointer

    Quote Originally Posted by Tischnoetentoet
    Hi all,

    I want to return a pointer to a COM interface.
    I have a COM interface ICollection. This interface has a function GetConnection. It should return a pointer to a IConnection object.

    Now I have this function:
    Code:
    CCollection::GetConnection(short index, IConnection * pConnection)
    {
        pConnection = m_arrConnections[index];
    
        return S_OK;
    }
    However, my compiler says:
    So, I think now I have to use ** instead of *. But then I get other compile errors.

    What is the right way to return an interface of a COM object?

    Thanks!
    Which "other compile errors" do you get?

  3. #3
    Join Date
    Nov 2003
    Posts
    2,185

    Re: Returning interface pointer

    WARNING:
    MIDL2039 : interface does not conform to [oleautomation] attribute
    The interface does not meet the requirements for and Automation interface. Check to make sure the interface is derived from IUnknown or IDispatch.

    The function definition has IConnection ** pConnection.

    Should I use IUnknown ** pConnection in this case?? If so, shall other languages such as VB still be able to get this IConnection object?

  4. #4
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Wallisellen (ZH), Switzerland
    Posts
    17,472

    Re: Returning interface pointer

    Quote Originally Posted by Tischnoetentoet
    WARNING:
    MIDL2039 : interface does not conform to [oleautomation] attribute
    The interface does not meet the requirements for and Automation interface. Check to make sure the interface is derived from IUnknown or IDispatch.

    The function definition has IConnection ** pConnection.

    Should I use IUnknown ** pConnection in this case?? If so, shall other languages such as VB still be able to get this IConnection object?
    Isn't your IConnection interface derived from IUnknown?
    From MSDN:
    Interfaces
    ...........
    Each interface is based on the fundamental COM interface, IUnknown. The methods of IUnknown allow navigation to other interfaces exposed by the object.

    Also, each interface is given a unique interface ID (IID). This uniqueness makes it is easy to support interface versioning. A new version of an interface is simply a new interface, with a new IID.
    ...............
    IUnknown

    IUnknown is the base interface of every other COM interface. IUnknown defines three methods: QueryInterface, AddRef, and Release.QueryInterface allows an interface user to ask the object for a pointer to another of its interfaces.AddRef andRelease implement reference counting on the interface
    ........

  5. #5
    Join Date
    Nov 2003
    Posts
    2,185

    Re: Returning interface pointer

    I am using IUnknown now, and it's working!

    Thanks a lot for your help!

Posting Permissions

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


Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center