OpenHome.Net.Core.InteropUtils.StringToHGlobalUtf8 C# (CSharp) Method

StringToHGlobalUtf8() public static method

public static StringToHGlobalUtf8 ( string aStr ) : IntPtr
aStr string
return System.IntPtr
        public static IntPtr StringToHGlobalUtf8(string aStr)
        {
            if (aStr == null)
                return IntPtr.Zero;
            byte[] bytes = System.Text.Encoding.UTF8.GetBytes(aStr);
            IntPtr ptr = Marshal.AllocHGlobal(bytes.Length + 1);
            Marshal.Copy(bytes, 0, ptr, bytes.Length);
            Marshal.WriteByte(ptr, bytes.Length, (byte)0);
            return ptr;
        }

Usage Example

Ejemplo n.º 1
0
        /// <summary>
        /// Claim a reference to the network adapter.
        /// </summary>
        /// <remarks>Can only be called from code that can guarantee another reference is already held.
        /// Each call to AddRef() must later have exactly one matching call to RemoveRef().</remarks>
        public void AddRef(string aCookie)
        {
            IntPtr cookie = InteropUtils.StringToHGlobalUtf8(aCookie);

            OhNetNetworkAdapterAddRef(iHandle, cookie);
            AddManagedCookie(aCookie, cookie);
        }
All Usage Examples Of OpenHome.Net.Core.InteropUtils::StringToHGlobalUtf8