Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / .NET Framework / CLR / December 2003

Tip: Looking for answers? Try searching our database.

__pin PtrToStringChars  

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Steve W TSI - 19 Nov 2003 17:31 GMT
#include <vcclr.h
To keep our code a little "cleaner" I'd like to encapsulate the converting of System::Strings to char pointers
I know putting the code in a function will not work because when the __pin goes out of scope, the string is no longer locked in memory

Would making the function inline work (keep the __pin in scope)
Is there anywhat to test this

Thanks, Steve

inline const __wchar_t * SysStringToLPCSTR(System::String *String

   const __wchar_t __pin * PinnedStr
   const __wchar_t       * PointerStr

   PinnedStr = PtrToStringChars(String)
   PointerStr = ( const __wchar_t *)(PinnedStr)
   return PointerStr
}
MS support - 01 Dec 2003 16:58 GMT
relying on inline isn't reliable. Instead, you can create
a pinning handle (see
System.Runtime.InteropServices.GCHandle) but you have to
Free it explicitly as soon as possible.
>-----Original Message-----
>#include <vcclr.h>
>To keep our code a little "cleaner" I'd like to encapsulate the converting of System::Strings to char
pointers.
>I know putting the code in a function will not work because when the __pin goes out of scope, the string is no
longer locked in memory.

>Would making the function inline work (keep the __pin in
scope)?
>Is there anywhat to test this?
>
>Thanks, Steve W
>
>inline const __wchar_t * SysStringToLPCSTR(System::String
*String)
>{
>    const __wchar_t __pin * PinnedStr;
[quoted text clipped - 5 lines]
>}
>.

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.