示例#1
0
        public unsafe void StringToHGlobalAnsiTest()
        {
            string input = "Input string";

            byte[] inputBytes = Encoding.ASCII.GetBytes(input + '\0');

            IntPtr pString = Marshal2.StringToHGlobalAnsi(input);

            byte *p = (byte *)pString;

            for (int i = 0; i < inputBytes.Length; i++)
            {
                Assert.AreEqual(*p, inputBytes[i]);
                p++;
            }

            Marshal.FreeHGlobal(pString);
        }