public static Guid CreateProviderContext( IntPtr sessionHandle, Guid providerId, DisplayData displayData, byte[] data) { var id = Guid.Empty; var dataPtr = IntPtr.Zero; var size = 0; if (data != null && (size = data.Length) != 0) { dataPtr = Marshal.AllocHGlobal(size); Marshal.Copy(data, 0, dataPtr, size); } try { AssertSuccess(() => PInvoke.CreateProviderContext( sessionHandle, ref displayData, ref providerId, (uint)size, dataPtr, ref id)); } finally { Marshal.FreeHGlobal(dataPtr); } return(id); }