예제 #1
0
        public static void Can_call_lpwstr_extern_function()
        {
            var buffer = Pointer.Create <LPWSTR>(Marshal.AllocCoTaskMem(2 * MAX_PATH));

            try
            {
                var length = GetSystemDirectoryW(buffer, MAX_PATH);
                if (length == 0)
                {
                    throw Marshal.GetExceptionForHR(Marshal.GetLastWin32Error());
                }
                var path = UnicodeStringPointer.MarshalToString(buffer, length);
                Assert.NotNull(path);
            }
            finally
            {
                Marshal.FreeCoTaskMem(buffer.Pointer);
            }
        }
예제 #2
0
        public static void Can_call_lpwstr_extern_function(COMPUTER_NAME_FORMAT nameType)
        {
            int length = 255;
            var buffer = Pointer.Create <LPWSTR>(Marshal.AllocCoTaskMem(2 * length));

            try
            {
                bool successful = GetComputerNameExW(nameType, buffer, ref length);
                if (!successful)
                {
                    throw Marshal.GetExceptionForHR(Marshal.GetLastWin32Error());
                }
                var path = UnicodeStringPointer.MarshalToString(buffer, length);
                Assert.NotNull(path);
            }
            finally
            {
                Marshal.FreeCoTaskMem(buffer.Pointer);
            }
        }