forked from ClearFoundry/ClearScript
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathActivationHelpers.cs
More file actions
28 lines (24 loc) · 809 Bytes
/
ActivationHelpers.cs
File metadata and controls
28 lines (24 loc) · 809 Bytes
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
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT license.
using System;
namespace Microsoft.ClearScript.Util.COM
{
internal static class ActivationHelpers
{
public static IntPtr CreateInstance<T>(string progID)
{
var clsid = CLSIDFromProgID(progID);
var iid = typeof(T).GUID;
HResult.Check(NativeMethods.CoCreateInstance(ref clsid, IntPtr.Zero, 1, ref iid, out var pInterface));
return pInterface;
}
private static Guid CLSIDFromProgID(string progID)
{
if (!Guid.TryParseExact(progID, "B", out var clsid))
{
HResult.Check(NativeMethods.CLSIDFromProgID(progID, out clsid));
}
return clsid;
}
}
}