-
Notifications
You must be signed in to change notification settings - Fork 7
/
ComUtilities.cs
28 lines (23 loc) · 1.04 KB
/
ComUtilities.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
using System;
using System.Runtime.InteropServices;
namespace SharpGen.Runtime
{
public static class ComUtilities
{
static ComUtilities() => ComActivationHelpers.CoInitialize();
public static void CreateComInstance(Guid classGuid, ComContext context, Guid interfaceGuid, ComObject comObject)
{
if (comObject == null) throw new ArgumentNullException(nameof(comObject));
var result = ComActivationHelpers.CreateComInstance(classGuid, context, interfaceGuid, out var pointer);
result.CheckError();
comObject.NativePointer = pointer;
}
public static bool TryCreateComInstance(Guid classGuid, ComContext context, Guid interfaceGuid, ComObject comObject)
{
if (comObject == null) throw new ArgumentNullException(nameof(comObject));
var result = ComActivationHelpers.CreateComInstance(classGuid, context, interfaceGuid, out var pointer);
comObject.NativePointer = pointer;
return result.Success;
}
}
}