-
February 15th, 2005, 07:31 AM
#1
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!
-
February 15th, 2005, 07:43 AM
#2
Re: Returning interface pointer
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?
-
February 15th, 2005, 07:54 AM
#3
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?
-
February 15th, 2005, 08:06 AM
#4
Re: Returning interface pointer
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
........
-
February 15th, 2005, 08:19 AM
#5
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|