I am playing around with the Marshal class in C# and am slightly confused by the result of this operation:
string someVal = "Hello There";
IntPtr ptS = Marshal.StringToHGlobalAnsi(someVal);
char* ptsPt = (char*)ptS.ToPointer();
After looking at ptsPt[0] in the immediate window it contains this value: '效'
I am guessing it has something to do with the StringToHGlobalAnsi
Method treating the managed chars as 8 bit values, but when they really they are 16 bit. But I cannot quite understand why this is happening.
I know I can get around this issue by changing it to StringToHGlobalUni
. But I don't understand why this is!
Cheers