PtrToStringChars in Vc7/include/vcclr.h

  • Thread starter Thread starter Eric Twietmeyer
  • Start date Start date
E

Eric Twietmeyer

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
 
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
 
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
 
Back
Top