COM object that returns a string

J

JustinInAtlanta

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
 
N

Nicholas Paldino [.NET/C# MVP]

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.
 
W

Willy Denoyette [MVP]

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top