Issue #23: implement sta runtime and message pump
This commit is contained in:
@@ -0,0 +1,31 @@
|
||||
using System;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
namespace MxGateway.Worker.Sta;
|
||||
|
||||
public sealed class StaComApartmentInitializer : IStaComApartmentInitializer
|
||||
{
|
||||
private const uint CoInitializeApartmentThreaded = 0x2;
|
||||
private const int SOk = 0;
|
||||
private const int SFalse = 1;
|
||||
|
||||
public void Initialize()
|
||||
{
|
||||
int hresult = CoInitializeEx(IntPtr.Zero, CoInitializeApartmentThreaded);
|
||||
if (hresult != SOk && hresult != SFalse)
|
||||
{
|
||||
throw new COMException("Failed to initialize the worker STA COM apartment.", hresult);
|
||||
}
|
||||
}
|
||||
|
||||
public void Uninitialize()
|
||||
{
|
||||
CoUninitialize();
|
||||
}
|
||||
|
||||
[DllImport("ole32.dll")]
|
||||
private static extern int CoInitializeEx(IntPtr reserved, uint coInit);
|
||||
|
||||
[DllImport("ole32.dll")]
|
||||
private static extern void CoUninitialize();
|
||||
}
|
||||
Reference in New Issue
Block a user