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 / Languages / Managed C++ / December 2003

Tip: Looking for answers? Try searching our database.

PtrToStringChars in Vc7/include/vcclr.h

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Eric Twietmeyer - 10 Dec 2003 23:27 GMT
In the header file vcclr.h (in the .../Vc7/include directory of your
installation) there is an inlined function PtrToStringChars defined.  This
is a utility function to get quick access to the internal chars of a
System::String object.  I came across it by reading Peter Grimes's "Managed
Extensions for Visual C++.NET" published by MSPress.

In any case, its implementation makes no sense to me.  The line that sets
offset calls the property OffsetToStringData on a static class called
RuntimeHelpers in the System::Runtime::CompilerServices namespace.

Strangely, there is no reference in this call to the property to the
underlying string, and yet the MSIL produces clearly shows that the String
reference is passed as the parameter to the get_OffsetToStringData method.
The syntax though in the c++ code does not indicate this in any way.

Clearly something strange is going on here.  Does anyone have an
explanation?  Is the compiler producing weird code because this is something
from the CompilerServices namespace, or do I not understand something about
managed c++ properties (very possible, I'm new to managed c++).

Very curious to understand what is going on.  Thanks,

-Eric
Mattias Sj?gren - 11 Dec 2003 00:11 GMT
Eric,

>Strangely, there is no reference in this call to the property to the
>underlying string,

There doesn't have to be, the offset is the same regardless of the
string.

>and yet the MSIL produces clearly shows that the String
>reference is passed as the parameter to the get_OffsetToStringData method.
>The syntax though in the c++ code does not indicate this in any way.

Are you sure you're not misinterpreting the IL code?
get_OffsetToStringData takes no parameters.

Mattias

Signature

Mattias Sjögren [MVP]  mattias @ mvps.org
http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com
Please reply only to the newsgroup.

Eric Twietmeyer - 11 Dec 2003 00:47 GMT
Matthias,

Thanks for the quick response.  That of course makes sense, the offset would
be the same regardless of the String object instance.  I was not
interpreting the MSIL correctly, as you surmised.  Thanks for the
clarification.

-Eric

> Eric,
>
[quoted text clipped - 12 lines]
>
> Mattias

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.