Exemplo n.º 1
0
        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);
        }
Exemplo n.º 2
0
        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);
        }
Exemplo n.º 3
0
 private unsafe static int Do_Abi_GetRuntimeClassName(IntPtr pThis, out IntPtr className)
 {
     className = default;
     try
     {
         string runtimeClassName = ComWrappersSupport.GetInspectableInfo(pThis).RuntimeClassName;
         className = MarshalString.FromManaged(runtimeClassName);
     }
     catch (Exception ex)
     {
         return(ex.HResult);
     }
     return(0);
 }
Exemplo n.º 4
0
        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();
            }
        }
Exemplo n.º 5
0
        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);
Exemplo n.º 6
0
        public static unsafe MarshalString CreateMarshaler(string value)
        {
            if (value == null)
            {
                return(null);
            }

            var         m       = new MarshalString();
            Func <bool> dispose = () => { m.Dispose(); return(false); };

            try
            {
                m._gchandle = GCHandle.Alloc(value, GCHandleType.Pinned);
                fixed(void *chars = value, header = &m._header, handle = &m._handle)
                {
                    Marshal.ThrowExceptionForHR(Platform.WindowsCreateStringReference(
                                                    (char *)chars, value.Length, (IntPtr *)header, (IntPtr *)handle));
                };
                return(m);
            }
            catch (Exception) when(dispose())
            {
                // Will never execute
                return(default);