CsWinRT
CsWinRT copied to clipboard
Add 'CoCreateInstance' helper
trafficstars
This PR adds the following APIs:
namespace WinRT;
public enum ClassContext : uint
{
InProcServer,
LocalServer
}
public class IInspectable
{
public static T CoCreateInstance<T>(in Guid classId, in Guid interfaceId, ClassContext classContext)
where T : class;
}
These can be used to easily create WinRT objects from out-of-proc COM servers.
For instance, for a Windows Package Manager type:
PackageManager packageManager = IInspectable.CoCreateInstance<PackageManager>(
CLSID_PackageManager,
IID_IPackageManager,
ClassContext.LocalServer);
As the IID is in the metadata for types, could we reference it that way instead of needing to declare it explicitly? (Sadly not true for CLSID)
Closing this, we're not really planning on adding new functionality to 2.x at this point. We can re-evaluate in the future whether we'd want a public API like this in 3.0, though the API surface and implementation would have to be different for sure.