Ureader.com  
Microsoft software help and Community
   home   |   control panel login   |   archive   |  
 
DotNet
acad.assignment.mngr
academic
adonet
aspnet
aspnet.announcements
aspnet.build.controls
aspnet.caching
aspnet.datagridcontrol
aspnet.mobile
aspnet.security
aspnet.webcontrols
aspnet.webservices
clr
compactframework
component_services
datatools
distributed_apps
drawing
faqs
framework
framework.wmi
general
internationalization
interop
languages.csharp
languages.jscript
languages.vb
languages.vb.controls
languages.vb.data
languages.vb.upgrade
languages.vc
languages.vc.libraries
myservices
odbcnet
performance
remoting
scripting
sdk
security
setup
vjsharp
vsa
webservi.enhancements
webservices
windowsforms
windowsforms.controls
winforms.databinding
winforms.designtime
xml
  
 
date: Wed, 18 Jun 2008 09:05:23 -0400,    group: microsoft.public.dotnet.framework.interop        back       


Proper way to return a string to C# from a C++ method. Manage code.   
I have a class in C++ and I am sure I have something declared wrong.

public ref class foobar
{
	public:

		String^ GetString()
			{
			return(gcnew String("null"));
			}			
}

Of course the real code is a little more complex, but not much.
This crashes the program in "release" mode, but works fine in
"debug" mode.  Which made it very difficult to track down.

What am I doing wrong?

thanks

-- 

Darryl Wagoner
DE WA1GON

Want a scholarship into the Millionaire Mind Intensive worth $2590?
http://www.secretsofthemillionairemind.com/a/?wid=603891

Crash programs fail because they operate under the theory
that nine pregnant women can deliver one baby in one month.
					-Werner von Braun


--------------=  Posted using GrabIt  =----------------
------=  Binary Usenet downloading made easy =---------
-=  Get GrabIt for free from http://www.shemes.com/  =-

** Posted from http://www.teranews.com **
date: Wed, 18 Jun 2008 09:05:23 -0400   author:   Darryl Wagoner

Re: Proper way to return a string to C# from a C++ method. Manage code.   
Those symptoms imply that it's being GC'd. Debug mode GC behaves differently 
(mainly so you can see debug values and not have them disappear on you).  As 
soon as you new it, it's disappearing, probably because of the interop layer 
and no references to the string.
The conventional thing to do IMO is to have te client pass a StringBuilder 
and have the C++ put data in there. If you look at pinvoke.net and all the 
Win32 Dll calls that's a common model for strings.

-- 
Phil Wilson

"Darryl Wagoner"  wrote in message 
news:89bc1$48590816$23972@news.teranews.com...
>I have a class in C++ and I am sure I have something declared wrong.
>
> public ref class foobar
> {
> public:
>
> String^ GetString()
> {
> return(gcnew String("null"));
> }
> }
>
> Of course the real code is a little more complex, but not much.
> This crashes the program in "release" mode, but works fine in
> "debug" mode.  Which made it very difficult to track down.
>
> What am I doing wrong?
>
> thanks
>
> -- 
>
> Darryl Wagoner
> DE WA1GON
>
> Want a scholarship into the Millionaire Mind Intensive worth $2590?
> http://www.secretsofthemillionairemind.com/a/?wid=603891
>
> Crash programs fail because they operate under the theory
> that nine pregnant women can deliver one baby in one month.
> -Werner von Braun
>
>
> --------------=  Posted using GrabIt  =----------------
> ------=  Binary Usenet downloading made easy =---------
> -=  Get GrabIt for free from http://www.shemes.com/  =-
>
> ** Posted from http://www.teranews.com **
date: Wed, 25 Jun 2008 08:01:07 -0700   author:   Phil Wilson

Google
 
Web ureader.com


    COPYRIGHT 2007, YARDI TECHNOLOGY LIMITED, ALL RIGHT RESERVE  |   contact us