HighTechTalks DotNet Forums  

COM object that returns a string

Dotnet Framework (Interop) microsoft.public.dotnet.framework.interop


Discuss COM object that returns a string in the Dotnet Framework (Interop) forum.



Reply
 
Thread Tools Search this Thread Display Modes
  #1  
Old   
JustinInAtlanta@gmail.com
 
Posts: n/a

Default COM object that returns a string - 12-20-2007 , 04:54 PM






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

Reply With Quote
  #2  
Old   
kishore
 
Posts: n/a

Default Re: COM object that returns a string - 12-29-2007 , 04:22 AM






use BSTR in C++ function.


<JustinInAtlanta (AT) gmail (DOT) com> wrote

Quote:
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



Reply With Quote
Reply




Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.4
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.