Interoperability
-
I am working on an application where I am using C# .net as well as ATL COM. I have created below classes 1) Class Add, Which is created using C# .Net. And which implement Addition functionality. This class uses IAdd interface which is having Add method to perform addition. (Please note that IAdd is an com interface and we have used it by creating interop dll)
public class Add : IAdd
{
#region IAdd Membersvoid IAdd.Add(double P1, double P2) { throw new Exception("The method or operation is not implemented."); } #endregion }
- Class Calculate (com visible component), which is created using C# .Net. And which internally uses Class ADD to perform addition. . (Please note that ICustom is an com interface and we have used it by creating interop dll)
class Calculate : ICustom
{
#region ICustom Members
Add add = new Add ();
#endregion#region ICustom Members void ICustom.CustomQueryInterface(Guid id, ref object ptr) { throw new Exception("The method or operation is not implemented."); } #endregion }
- Class Client, This class is created using ATL COM, which crates the object of class Calculate as “calculate“ and then tries to retrieve interface IAdd using object calculate. To get the IAdd interface, what I have done is I have created a Custom Interface which contain a method similar to the Query Interface () method available in the IUnknownInterface. This interface is then implemented by the class Calculate, Now whenever client requires an IADD interface pointer; it will use ICustomInterface to retrieve it. Please suggest: What should be the implementation Of .CustomQueryInterface(Guid id, ref object ptr)? Also what should be the code at client side (Client is implemented inCOM)
IDL file :
[
object,
uuid(E99CD31D-34FE-4AFF-A1E6-C438F73F685F),
dual,
nonextensible,
helpstring("ICOMClient Interface"),
pointer_default(unique)
]
interface ICOMClient : IDispatch{\[id(1), helpstring("method PerformCalculation")\] HRESULT PerformCalculation(void);
};
[
object,
uuid(53F4B9FA-B6E7-42aa-939B-97B93010270F),
dual,
nonextensible,
helpstring("IAdd Interface"),
pointer_default(unique)
]
interface IAdd : IUnknown{
[id(1), helpstring("method Add")] HRESULT Add([in] DOUBLE P1, [in] DOUBLE P2);
};[
object,
uuid(8C4DE0FA-6D4B-4c52-9E35 -
I am working on an application where I am using C# .net as well as ATL COM. I have created below classes 1) Class Add, Which is created using C# .Net. And which implement Addition functionality. This class uses IAdd interface which is having Add method to perform addition. (Please note that IAdd is an com interface and we have used it by creating interop dll)
public class Add : IAdd
{
#region IAdd Membersvoid IAdd.Add(double P1, double P2) { throw new Exception("The method or operation is not implemented."); } #endregion }
- Class Calculate (com visible component), which is created using C# .Net. And which internally uses Class ADD to perform addition. . (Please note that ICustom is an com interface and we have used it by creating interop dll)
class Calculate : ICustom
{
#region ICustom Members
Add add = new Add ();
#endregion#region ICustom Members void ICustom.CustomQueryInterface(Guid id, ref object ptr) { throw new Exception("The method or operation is not implemented."); } #endregion }
- Class Client, This class is created using ATL COM, which crates the object of class Calculate as “calculate“ and then tries to retrieve interface IAdd using object calculate. To get the IAdd interface, what I have done is I have created a Custom Interface which contain a method similar to the Query Interface () method available in the IUnknownInterface. This interface is then implemented by the class Calculate, Now whenever client requires an IADD interface pointer; it will use ICustomInterface to retrieve it. Please suggest: What should be the implementation Of .CustomQueryInterface(Guid id, ref object ptr)? Also what should be the code at client side (Client is implemented inCOM)
IDL file :
[
object,
uuid(E99CD31D-34FE-4AFF-A1E6-C438F73F685F),
dual,
nonextensible,
helpstring("ICOMClient Interface"),
pointer_default(unique)
]
interface ICOMClient : IDispatch{\[id(1), helpstring("method PerformCalculation")\] HRESULT PerformCalculation(void);
};
[
object,
uuid(53F4B9FA-B6E7-42aa-939B-97B93010270F),
dual,
nonextensible,
helpstring("IAdd Interface"),
pointer_default(unique)
]
interface IAdd : IUnknown{
[id(1), helpstring("method Add")] HRESULT Add([in] DOUBLE P1, [in] DOUBLE P2);
};[
object,
uuid(8C4DE0FA-6D4B-4c52-9E35this might help Using COM aware DotNet Library in MFC Application[^]
"Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow
Never mind - my own stupidity is the source of every "problem" - Mixturecheers, Alok Gupta VC Forum Q&A :- I/IV Support CRY- Child Relief and You