Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. Interoperability

Interoperability

Scheduled Pinned Locked Moved C#
csharpcomc++databasequestion
2 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • C Offline
    C Offline
    Chiman1
    wrote on last edited by
    #1

    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 Members

        void IAdd.Add(double P1, double P2)
        {
            throw new Exception("The method or operation is not implemented.");
        }
    
        #endregion
    }
    
    1. 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
        }
    
    1. 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

    T 1 Reply Last reply
    0
    • C Chiman1

      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 Members

          void IAdd.Add(double P1, double P2)
          {
              throw new Exception("The method or operation is not implemented.");
          }
      
          #endregion
      }
      
      1. 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
          }
      
      1. 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

      T Offline
      T Offline
      ThatsAlok
      wrote on last edited by
      #2

      this 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" - Mixture

      cheers, Alok Gupta VC Forum Q&A :- I/IV Support CRY- Child Relief and You

      1 Reply Last reply
      0
      Reply
      • Reply as topic
      Log in to reply
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes


      • Login

      • Don't have an account? Register

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • World
      • Users
      • Groups