COM Interop - exposing properties

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Luke Briner

    #1

    COM Interop - exposing properties

    My ActiveX Container requires certain properties to be exposed by
    components - properties that appear under the properties section in the
    IDL/type library file.

    C# properties are exposed as methods and the interfaces that my c# class
    implements cannot contain fields in order to expose these as properties.

    Can anyone tell me how to expose c# code as COM (IDL) properties.

    Thanks

  • José Joye

    #2
    Re: COM Interop - exposing properties

    Look there:

    http://msdn.microsoft.com/library/de...tnetserver.asp


    José


    "Luke Briner" <lukedotbriner@ cheerful.com> a écrit dans le message de
    news:bj2pum$3lr $1@hercules.bti nternet.com...[color=blue]
    > My ActiveX Container requires certain properties to be exposed by
    > components - properties that appear under the properties section in the
    > IDL/type library file.
    >
    > C# properties are exposed as methods and the interfaces that my c# class
    > implements cannot contain fields in order to expose these as properties.
    >
    > Can anyone tell me how to expose c# code as COM (IDL) properties.
    >
    > Thanks
    >[/color]


    Comment

    • Jay Douglas

      #3
      Re: COM Interop - exposing properties

      I was just going working through this issue on a different thread in this
      news group... This is what I finally came up with:

      using System;
      using System.Runtime. InteropServices ;

      namespace Squarei
      {
      //DEFINE THE PUBLIC INTERFACE FOR THE COM OBJECT
      public interface IComInteropTest
      {
      void SetHTML(string strHtml);
      string GetHTML();
      }


      //IMPLEMENT THE CLASS BELOW USING THE PUBLIC INTERFACE DEFINED ABOVE
      [ClassInterface( ClassInterfaceT ype.None)]
      public class ComInteropTest : IComInteropTest
      {

      public string strUrl = string.Empty;
      public string strHtml = string.Empty;

      public void SetHTML(string strHtml)
      {
      this.strHtml = strHtml;
      }

      public string GetHTML()
      {
      return strHtml;
      }
      }
      }

      --
      Jay Douglas
      Fort Collins, CO



      "Luke Briner" <lukedotbriner@ cheerful.com> wrote in message
      news:bj2pum$3lr $1@hercules.bti nternet.com...[color=blue]
      > My ActiveX Container requires certain properties to be exposed by
      > components - properties that appear under the properties section in the
      > IDL/type library file.
      >
      > C# properties are exposed as methods and the interfaces that my c# class
      > implements cannot contain fields in order to expose these as properties.
      >
      > Can anyone tell me how to expose c# code as COM (IDL) properties.
      >
      > Thanks
      >[/color]


      Comment

      • Luke Briner

        #4
        Re: COM Interop - exposing properties

        Thanks for the help but the MS website does not have any details and
        Jay's example still uses methods. I need to expose "idl properties" from
        C#. I don't mind how I write the C# code but my container must see the
        properties under the "properties " section in the idl file.

        Comment

        • Jay Douglas

          #5
          Re: COM Interop - exposing properties

          Sorry for providing the incorrect information ....

          I'm having issues obtaining the same goals as you. Here's the work around I
          came up with (I'm not satisfied with my solution, and it still uses methods)

          Say I have a property/field

          public string FirstName

          I then created the methods

          public void setFirstName(st ring s) {
          FirstName = s;
          }
          public string getFirstName() {
          return FirstName;
          }

          Then I exposed the methods in the interface.

          I would love to hear a better way to expose the properties.



          --
          Jay Douglas
          Fort Collins, CO



          "Luke Briner" <lukedotbriner@ cheerful.com> wrote in message
          news:bj5gri$k7n $1@titan.btinte rnet.com...[color=blue]
          > Thanks for the help but the MS website does not have any details and
          > Jay's example still uses methods. I need to expose "idl properties" from
          > C#. I don't mind how I write the C# code but my container must see the
          > properties under the "properties " section in the idl file.
          >[/color]


          Comment

          Working...