DotNetNewsgroup.com  
web access to complete list of Microsoft.NET newsgroups
   home   |   control panel login   |   archive  |  
 
  carried group
academic
adonet
aspnet
aspnet.announcements
aspnet.buildingcontrols
aspnet.caching
aspnet.datagridcontrol
aspnet.mobile
aspnet.security
aspnet.webcontrols
aspnet.webservices
assignment_manager
datatools
dotnet.distributed_apps
dotnet.general
dotnet.myservices
dotnet.nternationalization
dotnet.scripting
dotnet.security
dotnet.vjsharp
dotnet.vsa
dotnet.xml
dotnetfaqs
framework
framework.clr
framework.compactframework
framework.component_services
framework.controls
framework.databinding
framework.drawing
framework.enhancements
framework.interop
framework.odbcnet
framework.performance
framework.remoting
framework.sdk
framework.setup
framework.webservices
framework.windowsforms
framework.wmi
frwk.windowsforms.designtime
lang.csharp
lang.jscript
lang.vb
lang.vb.controls
lang.vb.data
lang.vb.upgrade
lang.vc
lang.vc.libraries
  
 
start date: Tue, 10 Jul 2007 16:58:45 -0700,    posted on: microsoft.public.dotnet.framework.interop        back       

Thread Index
  1    Roshan


How to marshal returned unicode string pointers   
Hi All,


>From my C# code, I am calling a native method which returns a PWSTR. I

receive the return value as a IntPtr and then marshal it to a string.
I notice that I get the correct return value if I use
Marshal.PtrToStringAnsi but not if I use PtrToStringAuto or
PtrToStringUni. How do I marshal the return value if the return value
is actually a unicode string?

  [DllImport("My.dll", SetLastError = true, CharSet =
CharSet.Unicode)]
  [return: MarshalAs(UnmanagedType.SysUInt)]
  public static extern IntPtr GetUnicodeString(
            [In] uint index);

Using it as

IntPtr myStr =GetUnicodeString(index);
String myString = Marshal.PtrToStringAnsi(myStr); // Works
String myString = Marshal.PtrToStringAuto (myStr); // Does not Work
String myString = Marshal.PtrToStringUni(myStr); // Does not Work

Does any one know how to return unicode strings?

Thanks,
RA
Date:Tue, 10 Jul 2007 16:58:45 -0700   Author:  

Google
 
Web dotnetnewsgroup.com


COPYRIGHT ?2005, EUROFRONT WORLDWIDE LTD., ALL RIGHT RESERVE  |   Contact us