COM object that returns a string

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • JustinInAtlanta@gmail.com

    #1

    COM object that returns a string

    Hello. I have written a Class Library in C# that has two methods:

    GetNumber returns 17
    GetName returns foo

    I am able to add a reference to the COM object from an ASP.NET page,
    call both methods, and display the correct results in labels on the
    Web page.

    I also want to be able to instantiate the COM object in a C++ program
    and call both methods. I can instantiate the COM object successfully.
    When I call GetNumber from the C++ program, I get 17. But, when I call
    GetName, I get garbage. I am guessing this has something to do with
    the marshalling and how it is handling strings. I need to be able to
    call the GetName method in the C# COM object from my C++ program to
    get foo.

    Does anyone have any ideas how to resolve this? Thanks in advance for
    your help.

    Justin
  • Nicholas Paldino [.NET/C# MVP]

    #2
    Re: COM object that returns a string

    Justin,

    Well, it shouldn't be too hard. However, you really should show the COM
    component implementation, as well as the C++ code that is making the call.

    --
    - Nicholas Paldino [.NET/C# MVP]
    - mvp@spam.guard. caspershouse.co m

    <JustinInAtlant a@gmail.comwrot e in message
    news:360ad15e-ac5a-4158-83b5-c92ac289c44e@x6 9g2000hsx.googl egroups.com...
    Hello. I have written a Class Library in C# that has two methods:
    >
    GetNumber returns 17
    GetName returns foo
    >
    I am able to add a reference to the COM object from an ASP.NET page,
    call both methods, and display the correct results in labels on the
    Web page.
    >
    I also want to be able to instantiate the COM object in a C++ program
    and call both methods. I can instantiate the COM object successfully.
    When I call GetNumber from the C++ program, I get 17. But, when I call
    GetName, I get garbage. I am guessing this has something to do with
    the marshalling and how it is handling strings. I need to be able to
    call the GetName method in the C# COM object from my C++ program to
    get foo.
    >
    Does anyone have any ideas how to resolve this? Thanks in advance for
    your help.
    >
    Justin

    Comment

    • Willy Denoyette [MVP]

      #3
      Re: COM object that returns a string

      <JustinInAtlant a@gmail.comwrot e in message
      news:360ad15e-ac5a-4158-83b5-c92ac289c44e@x6 9g2000hsx.googl egroups.com...
      Hello. I have written a Class Library in C# that has two methods:
      >
      GetNumber returns 17
      GetName returns foo
      >
      I am able to add a reference to the COM object from an ASP.NET page,
      call both methods, and display the correct results in labels on the
      Web page.
      >
      I also want to be able to instantiate the COM object in a C++ program
      and call both methods. I can instantiate the COM object successfully.
      When I call GetNumber from the C++ program, I get 17. But, when I call
      GetName, I get garbage. I am guessing this has something to do with
      the marshalling and how it is handling strings. I need to be able to
      call the GetName method in the C# COM object from my C++ program to
      get foo.
      >
      Does anyone have any ideas how to resolve this? Thanks in advance for
      your help.
      >
      Justin

      System.String is marshaled as BSTR (length prefixed Unicode strings), do you
      treat them as such at the client?

      Willy.

      Comment

      Working...