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. COM and C#.net Interoperability

COM and C#.net Interoperability

Scheduled Pinned Locked Moved C#
csharpc++questiondatabasecom
6 Posts 5 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.
  • V Offline
    V Offline
    Vijjuuu
    wrote on last edited by
    #1

    Hi all, i am trying to expose C# object to COM and in this process i got a query and not sure how to progress further. so here i am seeking for help. i want to define a interface in C# in such a way the consumer of the COM object should be able to use the method in the following way. comObject.methodName(123) the above statement will return a value, assume where 123 is the parameter which could id or some thing like that comObject.methodName(123) = 100 the above statement should set the value 100 something internal member having id 123 in both the above statement the methodName is the same. so the question is how can we define an interface in C# that can be exposed to COM using regasm.exe. i know it is possible to define such a way in C++ using ATL but not sure how can i achieve the same in C#. [Comvisible(true)] interface ExposeToCom { // don't know what all to add to make the method appear to COM to be get and set int methodName(int); } Thanks for your help,

    L B B 3 Replies Last reply
    0
    • V Vijjuuu

      Hi all, i am trying to expose C# object to COM and in this process i got a query and not sure how to progress further. so here i am seeking for help. i want to define a interface in C# in such a way the consumer of the COM object should be able to use the method in the following way. comObject.methodName(123) the above statement will return a value, assume where 123 is the parameter which could id or some thing like that comObject.methodName(123) = 100 the above statement should set the value 100 something internal member having id 123 in both the above statement the methodName is the same. so the question is how can we define an interface in C# that can be exposed to COM using regasm.exe. i know it is possible to define such a way in C++ using ATL but not sure how can i achieve the same in C#. [Comvisible(true)] interface ExposeToCom { // don't know what all to add to make the method appear to COM to be get and set int methodName(int); } Thanks for your help,

      L Offline
      L Offline
      Lost User
      wrote on last edited by
      #2

      Lots of samples around: com c - Google Search[^]

      1 Reply Last reply
      0
      • V Vijjuuu

        Hi all, i am trying to expose C# object to COM and in this process i got a query and not sure how to progress further. so here i am seeking for help. i want to define a interface in C# in such a way the consumer of the COM object should be able to use the method in the following way. comObject.methodName(123) the above statement will return a value, assume where 123 is the parameter which could id or some thing like that comObject.methodName(123) = 100 the above statement should set the value 100 something internal member having id 123 in both the above statement the methodName is the same. so the question is how can we define an interface in C# that can be exposed to COM using regasm.exe. i know it is possible to define such a way in C++ using ATL but not sure how can i achieve the same in C#. [Comvisible(true)] interface ExposeToCom { // don't know what all to add to make the method appear to COM to be get and set int methodName(int); } Thanks for your help,

        B Offline
        B Offline
        Bernhard Hiller
        wrote on last edited by
        #3

        You are use a method as if it was a property. You cannot assign a value to a function! Rather think of comObject.methodName(123, 100), i.e. a function with 2 parameters (key and value).

        V 1 Reply Last reply
        0
        • B Bernhard Hiller

          You are use a method as if it was a property. You cannot assign a value to a function! Rather think of comObject.methodName(123, 100), i.e. a function with 2 parameters (key and value).

          V Offline
          V Offline
          Vijjuuu
          wrote on last edited by
          #4

          Thanks for your response. Actually, i am trying re-write a COM component developed in ATL which is production. i want to give the same interface so that consumer has minimal impact. code snippet from my existence code.

          STDMETHOD(get\_methodA)(/\*\[in\]\*/ VARIANT storeID, /\*\[out, retval\]\*/ VARIANT \*pVal);
          STDMETHOD(put\_methodA)(/\*\[in\]\*/ VARIANT storeID, /\*\[in\]\*/ VARIANT newVal);
          STDMETHOD(get\_methodB)(/\*\[in\]\*/ VARIANT storeID, /\*\[in\]\*/ VARIANT index, /\*\[out, retval\]\*/ VARIANT \*pVal);
          STDMETHOD(put\_methodB)(/\*\[in\]\*/ VARIANT storeID, /\*\[in\]\*/ VARIANT index, /\*\[in\]\*/ VARIANT newVal);
          

          when i extract the typelib for this

          [id(0x00000001), propget, helpstring("property methodA")]
          HRESULT methodA([in] VARIANT storeID, [out, retval] VARIANT* pVal);

          \[id(0x00000001), propput, helpstring("property methodA")\]
          HRESULT methodA(\[in\] VARIANT storeID, \[in\] VARIANT pVal);
          
          
          \[id(0x00000004), propget, helpstring("property methodB")\]
          HRESULT methodB(\[in\] VARIANT storeID, \[in\] VARIANT index, \[out, retval\] VARIANT\* pVal);
          
          
          \[id(0x00000004), propput, helpstring("property methodB")\]
          HRESULT methodB(\[in\] VARIANT storeID, \[in\] VARIANT index, \[in\] VARIANT pVal);
          

          so the consumer can use as methodA(123) -- return a value methodA(123) = 100 -- this will set a value methodB(123, 3) -- return a value methodB(123, 3) = 100 -- this will set a value. i am trying to mimic the same methods defined in my ATL in a C# interface and use .net com interoperability using a regasm. i am not able to find out how achieve this in C#. if this is done in ATL i was thinking there could be a way to achieve this. thanks for your time

          P 1 Reply Last reply
          0
          • V Vijjuuu

            Thanks for your response. Actually, i am trying re-write a COM component developed in ATL which is production. i want to give the same interface so that consumer has minimal impact. code snippet from my existence code.

            STDMETHOD(get\_methodA)(/\*\[in\]\*/ VARIANT storeID, /\*\[out, retval\]\*/ VARIANT \*pVal);
            STDMETHOD(put\_methodA)(/\*\[in\]\*/ VARIANT storeID, /\*\[in\]\*/ VARIANT newVal);
            STDMETHOD(get\_methodB)(/\*\[in\]\*/ VARIANT storeID, /\*\[in\]\*/ VARIANT index, /\*\[out, retval\]\*/ VARIANT \*pVal);
            STDMETHOD(put\_methodB)(/\*\[in\]\*/ VARIANT storeID, /\*\[in\]\*/ VARIANT index, /\*\[in\]\*/ VARIANT newVal);
            

            when i extract the typelib for this

            [id(0x00000001), propget, helpstring("property methodA")]
            HRESULT methodA([in] VARIANT storeID, [out, retval] VARIANT* pVal);

            \[id(0x00000001), propput, helpstring("property methodA")\]
            HRESULT methodA(\[in\] VARIANT storeID, \[in\] VARIANT pVal);
            
            
            \[id(0x00000004), propget, helpstring("property methodB")\]
            HRESULT methodB(\[in\] VARIANT storeID, \[in\] VARIANT index, \[out, retval\] VARIANT\* pVal);
            
            
            \[id(0x00000004), propput, helpstring("property methodB")\]
            HRESULT methodB(\[in\] VARIANT storeID, \[in\] VARIANT index, \[in\] VARIANT pVal);
            

            so the consumer can use as methodA(123) -- return a value methodA(123) = 100 -- this will set a value methodB(123, 3) -- return a value methodB(123, 3) = 100 -- this will set a value. i am trying to mimic the same methods defined in my ATL in a C# interface and use .net com interoperability using a regasm. i am not able to find out how achieve this in C#. if this is done in ATL i was thinking there could be a way to achieve this. thanks for your time

            P Offline
            P Offline
            Pete OHanlon
            wrote on last edited by
            #5

            If you have a type library, you can convert it into a .NET assembly using tlbimp.

            This space for rent

            1 Reply Last reply
            0
            • V Vijjuuu

              Hi all, i am trying to expose C# object to COM and in this process i got a query and not sure how to progress further. so here i am seeking for help. i want to define a interface in C# in such a way the consumer of the COM object should be able to use the method in the following way. comObject.methodName(123) the above statement will return a value, assume where 123 is the parameter which could id or some thing like that comObject.methodName(123) = 100 the above statement should set the value 100 something internal member having id 123 in both the above statement the methodName is the same. so the question is how can we define an interface in C# that can be exposed to COM using regasm.exe. i know it is possible to define such a way in C++ using ATL but not sure how can i achieve the same in C#. [Comvisible(true)] interface ExposeToCom { // don't know what all to add to make the method appear to COM to be get and set int methodName(int); } Thanks for your help,

              B Offline
              B Offline
              BenScharbach
              wrote on last edited by
              #6

              Not sure, but I believe you have to turn on this feature in the AssemblyInfo page. Then, you have to put it on the Type you want to make visible.

              // Setting ComVisible to false makes the types in this assembly not visible
              // to COM components. If you need to access a type in this assembly from
              // COM, set the ComVisible attribute to true on that type.

              Ben Scharbach Temporalwars.Com YouTube:Ben Scharbach

              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