Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Query :Basic Concept of COM Regarding IUnknown interface 1

Status
Not open for further replies.

Dennis7

Programmer
Dec 10, 2001
6
0
0
IN
Dear Friends,
I have a basic doubt in IUnknown interface.

I have two COM Interfaces IX and IY.Class CA implements these two interfaces.

CA *pCA=new CA;
IUnKnown *pIX=static_cast<IUnknown *>(static_cast<IX *>(pCA));

IUnKnown *pIY=static_cast<IUnknown *>(static_cast<IY *>(pCA))

whether these two pointer will have same contents.
I did it and they contain different addresses.

This contradicts the Concept of COM that whenever u query for IUnknown pointer from any interface,the result will be same.so why the above code gives different addresses.

Waiting for ur Reply




 
You are correct in your assertion, IUnknown interface pointers returned from a server object are REQUIRED to be equal. In fact this is the ONLY valid way for a client to test for pointers to the same object.

However, it is the responsibility of the object itself to implement IUnknown::QueryInterface to ensure that it always returns an identical IUnknown pointer to all clients. Given this, the problem will probably lie in implementation of thr COM object itself.

Finally, your code above looks strange to me. Normall client code instantiates COM objects using CoCreateInstance (or a combination of CoGetClassObject and IClassfactory::CreateInstance), NOT by direct instantiation on the heap. You code above would certainly not work for Local or Remote servers, and would not be guaranteed to work even for in-process servers.

Hope this help.

Biffa
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top