>Yes but can you. I downloaded some sample code from a MSFT developer who
>relies on low-level techniques for this. He seems to imply by one of his
comments that you need to rely on low-level methods. I'd much rather rely on
"string" of course but how?
It doesn't always work, but you can easily try it simply by changing
the field type from IntPtr to string.
>Ok, but in theory I don't know if it will always be two bytes. I can't
assume an integer either (2 bytes or otherwise). While it will work for
Unicode on Win32, tt's really the OS's native "char" I need to work with
(whatever its size is) so a neutral way is required. If you have a Win32
background then it's whatever TCHAR natively maps to..
Well sizeof(TCHAR) can only be one or two bytes on all current
platforms that I know of, so by always writing two bytes you ensure
that at least as many bytes as needed are zeroed out.
But you can certainly take the native char size into account if you
want.
if (Marshal.SystemDefaultCharSize == 1)
Marshal.WriteByte(ptr, 0);
else
Marshal.WriteInt16(ptr, 0);
of if you want to be really dynamic
byte[] zeros = new byte[Marshal.SystemDefaultCharSize];
Marshal.Copy(zeros, 0, ptr, zeros.Length);
Mattias
--
Mattias Sjögren [C# MVP] mattias @ mvps.org
http://www.msjogren.net/dotnet/ |
http://www.dotnetinterop.com
Please reply only to the newsgroup.