public unsafe (ObjectReference <IActivationFactoryVftbl> obj, int hr) GetActivationFactory(string runtimeClassId) { IntPtr instancePtr; var hstrRuntimeClassId = MarshalString.CreateMarshaler(runtimeClassId); int hr = _GetActivationFactory(MarshalString.GetAbi(hstrRuntimeClassId), out instancePtr); return(hr == 0 ? ObjectReference <IActivationFactoryVftbl> .Attach(ref instancePtr) : null, hr); }
public static unsafe (ObjectReference <IActivationFactoryVftbl> obj, int hr) GetActivationFactory(string runtimeClassId) { var module = Instance; // Ensure COM is initialized Guid iid = typeof(IActivationFactoryVftbl).GUID; IntPtr instancePtr; var hstrRuntimeClassId = MarshalString.CreateMarshaler(runtimeClassId); int hr = Platform.RoGetActivationFactory(MarshalString.GetAbi(hstrRuntimeClassId), ref iid, &instancePtr); return(hr == 0 ? ObjectReference <IActivationFactoryVftbl> .Attach(ref instancePtr) : null, hr); }
public static unsafe (ObjectReference <IActivationFactoryVftbl> obj, int hr) GetActivationFactory(string runtimeClassId) { // TODO: "using var" with ref struct and remove the try/catch below var m = MarshalString.CreateMarshaler(runtimeClassId); try { IntPtr instancePtr; int hr; (instancePtr, hr) = GetActivationFactory(MarshalString.GetAbi(m)); return(hr == 0 ? ObjectReference <IActivationFactoryVftbl> .Attach(ref instancePtr) : null, hr); } finally { m.Dispose(); } }
public static unsafe (ObjectReference <IActivationFactoryVftbl> obj, int hr) GetActivationFactory(string runtimeClassId) { // TODO: "using var" with ref struct and remove the try/catch below var m = MarshalString.CreateMarshaler(runtimeClassId); Func <bool> dispose = () => { m.Dispose(); return(false); }; try { IntPtr instancePtr; int hr; (instancePtr, hr) = GetActivationFactory(MarshalString.GetAbi(m)); return(hr == 0 ? ObjectReference <IActivationFactoryVftbl> .Attach(ref instancePtr) : null, hr); } catch (Exception) when(dispose()) { // Will never execute return(default);