<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="http://blogs.msdn.com/utility/FeedStylesheets/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/"><channel><title>Pointer to String chars - Everett style</title><link>http://blogs.msdn.com/arich/archive/2003/12/22/45219.aspx</link><description>Garrett asked: If the source text is in a CLR String, and we want to pass(even read-only) to unmanaged code, it appears that there is no way to get a pointer to the String's buffer directly. We have to use the marshalling stuff to get it there, which</description><dc:language>en-US</dc:language><generator>CommunityServer 2.1 SP1 (Build: 61025.2)</generator><item><title>re: Pointer to String chars - Everett style</title><link>http://blogs.msdn.com/arich/archive/2003/12/22/45219.aspx#45454</link><pubDate>Tue, 23 Dec 2003 16:33:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:45454</guid><dc:creator>Garrett Serack</dc:creator><description>Sweet Mother Of all that is Good and Holy.&lt;br&gt;&lt;br&gt;    #include &amp;lt;vcclr.h&amp;gt;&lt;br&gt;&lt;br&gt;I'm a little unclear how that escaped me all this time--Probably 'cause I neglected to read any documentation when Everett came out, I just upgraded and moved on. I don't mind wchar_t* 's : It's what I wanted all along.&lt;br&gt;&lt;br&gt;*sigh* -- Must be a sign to find a complete management job :)&lt;br&gt;&lt;br&gt;Yeah, pin pointers rock. :) -- And you sure are correct about the need to use them as little and quickly as possible.&lt;br&gt;&lt;br&gt;I've been pretty strict about their usage, just to be safe. I typically have built a few macros/inline functions to handle pinning, to guarantee they have limited lifespan.&lt;br&gt;&lt;br&gt;Now, I just looked at the vcclr.h file. &lt;br&gt;&lt;br&gt;inline const System::Char * PtrToStringChars(const System::String *s) {&lt;br&gt;&lt;br&gt;   const System::Byte *bp = reinterpret_cast&amp;lt;const System::Byte *&amp;gt;(s);&lt;br&gt;   if( bp != 0 ) {&lt;br&gt;      unsigned offset = System::Runtime::CompilerServices::RuntimeHelpers::OffsetToStringData;&lt;br&gt;      bp += offset;&lt;br&gt;   }&lt;br&gt;    return reinterpret_cast&amp;lt;const System::Char*&amp;gt;(bp);&lt;br&gt;}&lt;br&gt;&lt;br&gt;I considered doing something like that by hand, as a method of finding the beginning of the string, but I discarded the thought, as I wasn't sure if the offset into the class would be constant, and didn't want to risk buggering up in future CLR versions. Sure nice of there to be a constant declared for that :)&lt;br&gt;&lt;br&gt;G&lt;br&gt;&lt;br&gt;</description></item><item><title>re: Pointer to String chars - Everett style</title><link>http://blogs.msdn.com/arich/archive/2003/12/22/45219.aspx#45458</link><pubDate>Tue, 23 Dec 2003 16:40:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:45458</guid><dc:creator>arich</dc:creator><description>Yeah, I'm actually not sure if the offset into the class is a constant or not, as the function uses the OffsetToStringData method of the runtime.  &lt;br&gt;&lt;br&gt;Upon ildasming mscorlib.dll (which everyone should do from time to time, just to see what's in it), it looks as though the offset is 12 - but this probably varies by architecture.</description></item><item><title>re: Pointer to String chars - Everett style</title><link>http://blogs.msdn.com/arich/archive/2003/12/22/45219.aspx#45474</link><pubDate>Tue, 23 Dec 2003 17:52:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:45474</guid><dc:creator>Garrett Serack</dc:creator><description>Speaking of ildasm -- I was thinking that it'd be nice if some of these type utilities were built into Visual Studio. I'm trying to do mentoring on the finer points of software devleopment with some folks and I find that they are less likely to use tools that are external to the development environment. (*sigh*--kids these days ;)&lt;br&gt;&lt;br&gt;That, and developer MSIL support in VS.NET would be nice too.&lt;br&gt;&lt;br&gt;Heck, while I'm at it, can I get a pony?&lt;br&gt;&lt;br&gt;Garrett</description></item><item><title>Pinning Pointers</title><link>http://blogs.msdn.com/arich/archive/2003/12/22/45219.aspx#221591</link><pubDate>Fri, 27 Aug 2004 20:32:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:221591</guid><dc:creator>I Love that New Syntax Smell</dc:creator><description /></item><item><title>Easily passing Managed strings to Unmanaged code (round 2)</title><link>http://blogs.msdn.com/arich/archive/2003/12/22/45219.aspx#372455</link><pubDate>Mon, 14 Feb 2005 21:58:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:372455</guid><dc:creator>Mike Stall's .NET Debugging Blog</dc:creator><description /></item><item><title>Easily passing Managed strings to Unmanaged code (round 2)</title><link>http://blogs.msdn.com/arich/archive/2003/12/22/45219.aspx#400603</link><pubDate>Tue, 22 Mar 2005 22:56:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:400603</guid><dc:creator>Mike Stall's .NET Debugging Blog</dc:creator><description /></item><item><title>Pinning Pointers</title><link>http://blogs.msdn.com/arich/archive/2003/12/22/45219.aspx#450156</link><pubDate>Thu, 11 Aug 2005 02:11:41 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:450156</guid><dc:creator>I Love that New Syntax Smell</dc:creator><description>Hot on the heels of my article on interior pointers, comes a much more insightful one by Stan Lippman...</description></item><item><title> I Love that New Syntax Smell Pointer to String chars Everett style | Outdoor Ceiling Fans</title><link>http://blogs.msdn.com/arich/archive/2003/12/22/45219.aspx#9667514</link><pubDate>Sun, 31 May 2009 09:52:52 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9667514</guid><dc:creator> I Love that New Syntax Smell Pointer to String chars Everett style | Outdoor Ceiling Fans</dc:creator><description>&lt;p&gt;PingBack from &lt;a rel="nofollow" target="_new" href="http://outdoorceilingfansite.info/story.php?id=3178"&gt;http://outdoorceilingfansite.info/story.php?id=3178&lt;/a&gt;&lt;/p&gt;
</description></item><item><title> I Love that New Syntax Smell Pointer to String chars Everett style | Outdoor Decor</title><link>http://blogs.msdn.com/arich/archive/2003/12/22/45219.aspx#9778781</link><pubDate>Fri, 19 Jun 2009 07:01:58 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9778781</guid><dc:creator> I Love that New Syntax Smell Pointer to String chars Everett style | Outdoor Decor</dc:creator><description>&lt;p&gt;PingBack from &lt;a rel="nofollow" target="_new" href="http://outdoordecoration.info/story.php?id=3223"&gt;http://outdoordecoration.info/story.php?id=3223&lt;/a&gt;&lt;/p&gt;
</description></item></channel></rss>