Browse Source

Merge pull request #1583 from zii-dmg/better-oleinitialize

OleInitialize checks already inited case and throws Win32Exception
pull/1519/merge
Jeremy Koritzinsky 8 years ago
committed by GitHub
parent
commit
791685bae6
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 8
      src/Windows/Avalonia.Win32/OleContext.cs

8
src/Windows/Avalonia.Win32/OleContext.cs

@ -1,4 +1,5 @@
using System;
using System.ComponentModel;
using System.Threading;
using Avalonia.Platform;
using Avalonia.Threading;
@ -26,8 +27,11 @@ namespace Avalonia.Win32
private OleContext()
{
if (UnmanagedMethods.OleInitialize(IntPtr.Zero) != UnmanagedMethods.HRESULT.S_OK)
throw new SystemException("Failed to initialize OLE");
UnmanagedMethods.HRESULT res = UnmanagedMethods.OleInitialize(IntPtr.Zero);
if (res != UnmanagedMethods.HRESULT.S_OK &&
res != UnmanagedMethods.HRESULT.S_FALSE /*already initialized*/)
throw new Win32Exception((int)res, "Failed to initialize OLE");
}
private static bool IsValidOleThread()

Loading…
Cancel
Save