Query Interface from Another Interface of Same Com Server
-
Hai all, I have two ATL Objects in my COM Server. Their interfaces are 1) IFirstIFC 2) ISecondIFC In my client programme I have imported the type library and using code below obtained the COM Object of IFirstIFC IFirstIFCPtr fIF; fIF.CreateInstance(__uuidof(FirstIFC)); Now my task is to obtain the COM Object of ISecondIFC. My Question is , Is there any method for Obtaining the Interface Pointer of ISecondFC by not calling again CreateInstance for that Interface. That is by avoiding this Code ISecondIFCPtr sIF; sIF.CreateInstance(__uuidof(SecondIFC)); That is,since both Interfaces are residing in the same COM Server, Can I get the Interface Pointer of ISecondFC through IFirstIFC. Thanks George
-
Hai all, I have two ATL Objects in my COM Server. Their interfaces are 1) IFirstIFC 2) ISecondIFC In my client programme I have imported the type library and using code below obtained the COM Object of IFirstIFC IFirstIFCPtr fIF; fIF.CreateInstance(__uuidof(FirstIFC)); Now my task is to obtain the COM Object of ISecondIFC. My Question is , Is there any method for Obtaining the Interface Pointer of ISecondFC by not calling again CreateInstance for that Interface. That is by avoiding this Code ISecondIFCPtr sIF; sIF.CreateInstance(__uuidof(SecondIFC)); That is,since both Interfaces are residing in the same COM Server, Can I get the Interface Pointer of ISecondFC through IFirstIFC. Thanks George
:confused::confused: A COM server is a COM object. This means that you actually have two servers. They may be located in the same file, but that's another thing. You cannot get an interface to an object without creating it. My suggestion: You could have the first server implement an interface method that will create the second server and by that you can avoid calling
CreateInstance()
from your client, but you would still have to callCreateInstance()
from your first server in order to create the second one.
"It's supposed to be hard, otherwise anybody could do it!" - selfquote
"High speed never compensates for wrong direction!" - unknown -
:confused::confused: A COM server is a COM object. This means that you actually have two servers. They may be located in the same file, but that's another thing. You cannot get an interface to an object without creating it. My suggestion: You could have the first server implement an interface method that will create the second server and by that you can avoid calling
CreateInstance()
from your client, but you would still have to callCreateInstance()
from your first server in order to create the second one.
"It's supposed to be hard, otherwise anybody could do it!" - selfquote
"High speed never compensates for wrong direction!" - unknownHai Roger, I got it. Thank you very much. I have another Doubt. Is all COM communications(between COM Server and Client) happening through RPC. Bcz, I have seen RPC header files such as "rpc.h" "rpcndr.h" in both the COM Exe and COM Dll. Thanks George
-
Hai Roger, I got it. Thank you very much. I have another Doubt. Is all COM communications(between COM Server and Client) happening through RPC. Bcz, I have seen RPC header files such as "rpc.h" "rpcndr.h" in both the COM Exe and COM Dll. Thanks George
georgekjolly wrote:
Is all COM communications(between COM Server and Client) happening through RPC
No. The most common way is to create an in-process-server running in the same thread, i.e. a single threaded apartment (STA). In this case every call to the server is exactly like an ordinary function call. Remote Procedure Call (RPC) will be used when you're marshalling interfaces between multiple threads. To get a deeper understanding of marshalling and RPC I suggest you read Lim Bio Liong's excellent article serie starting here[^].
"It's supposed to be hard, otherwise anybody could do it!" - selfquote
"High speed never compensates for wrong direction!" - unknown -
georgekjolly wrote:
Is all COM communications(between COM Server and Client) happening through RPC
No. The most common way is to create an in-process-server running in the same thread, i.e. a single threaded apartment (STA). In this case every call to the server is exactly like an ordinary function call. Remote Procedure Call (RPC) will be used when you're marshalling interfaces between multiple threads. To get a deeper understanding of marshalling and RPC I suggest you read Lim Bio Liong's excellent article serie starting here[^].
"It's supposed to be hard, otherwise anybody could do it!" - selfquote
"High speed never compensates for wrong direction!" - unknownHi Sir, Thank you very much for your help. Regards and Thanks George K J