Пример #1
0
        public static IntPtr HeapCreate(uint options, UIntPtr initialSize, UIntPtr maximumSize)
        {
            if (MiscHelpers.PlatformIsWindows())
            {
                return(NativeWindowsMethods.HeapCreate(options, initialSize, maximumSize));
            }

            throw new PlatformNotSupportedException();
        }
Пример #2
0
        public static IntPtr HeapAlloc(IntPtr hHeap, uint flags, UIntPtr size)
        {
            if (MiscHelpers.PlatformIsWindows())
            {
                return(NativeWindowsMethods.HeapAlloc(hHeap, flags, size));
            }

            throw new PlatformNotSupportedException();
        }
Пример #3
0
        public static uint ProgIDFromCLSID(ref Guid clsid, out string progID)
        {
            if (MiscHelpers.PlatformIsWindows())
            {
                return(NativeWindowsMethods.ProgIDFromCLSID(ref clsid, out progID));
            }

            throw new PlatformNotSupportedException();
        }
Пример #4
0
        public static uint VariantClear(IntPtr pVariant)
        {
            if (MiscHelpers.PlatformIsWindows())
            {
                return(NativeWindowsMethods.VariantClear(pVariant));
            }

            throw new PlatformNotSupportedException();
        }
Пример #5
0
        public static uint CoCreateInstance(ref Guid clsid, IntPtr pOuter, uint clsContext, ref Guid iid, out IntPtr pInterface)
        {
            if (MiscHelpers.PlatformIsWindows())
            {
                return(NativeWindowsMethods.CoCreateInstance(ref clsid, pOuter, clsContext, ref iid, out pInterface));
            }

            throw new PlatformNotSupportedException();
        }
Пример #6
0
        public static bool FreeLibrary(IntPtr hLibrary)
        {
            if (MiscHelpers.PlatformIsWindows())
            {
                return(NativeWindowsMethods.FreeLibrary(hLibrary));
            }

            throw new PlatformNotSupportedException();
        }
Пример #7
0
        public static uint CLSIDFromProgID(string progID, out Guid clsid)
        {
            if (MiscHelpers.PlatformIsWindows())
            {
                return(NativeWindowsMethods.CLSIDFromProgID(progID, out clsid));
            }

            throw new PlatformNotSupportedException();
        }
Пример #8
0
        public static bool HeapDestroy(IntPtr hHeap)
        {
            if (MiscHelpers.PlatformIsWindows())
            {
                return(NativeWindowsMethods.HeapDestroy(hHeap));
            }

            throw new PlatformNotSupportedException();
        }
Пример #9
0
        public static bool VirtualProtect(IntPtr pBlock, UIntPtr size, uint newProtect, out uint oldProtect)
        {
            if (MiscHelpers.PlatformIsWindows())
            {
                return(NativeWindowsMethods.VirtualProtect(pBlock, size, newProtect, out oldProtect));
            }

            throw new PlatformNotSupportedException();
        }
Пример #10
0
        public static bool HeapFree(IntPtr hHeap, uint flags, IntPtr pBlock)
        {
            if (MiscHelpers.PlatformIsWindows())
            {
                return(NativeWindowsMethods.HeapFree(hHeap, flags, pBlock));
            }

            throw new PlatformNotSupportedException();
        }
Пример #11
0
        public static IntPtr LoadLibraryW(string path)
        {
            if (MiscHelpers.PlatformIsWindows())
            {
                return(NativeWindowsMethods.LoadLibraryW(path));
            }

            throw new PlatformNotSupportedException();
        }
Пример #12
0
 public static void VariantInit(IntPtr pVariant)
 {
     if (MiscHelpers.PlatformIsWindows())
     {
         NativeWindowsMethods.VariantInit(pVariant);
     }
     else
     {
         throw new PlatformNotSupportedException();
     }
 }
Пример #13
0
 public static void GetNativeSystemInfo(out SystemInfo info)
 {
     if (MiscHelpers.PlatformIsWindows())
     {
         NativeWindowsMethods.GetNativeSystemInfo(out info);
     }
     else
     {
         throw new PlatformNotSupportedException();
     }
 }
Пример #14
0
        public static string GetLoadLibraryErrorMessage()
        {
            if (MiscHelpers.PlatformIsWindows())
            {
                return(new Win32Exception().Message);
            }

            if (MiscHelpers.PlatformIsLinux())
            {
                return(Marshal.PtrToStringAnsi(NativeLinuxMethods.GetLoadLibraryErrorMessage()));
            }

            if (MiscHelpers.PlatformIsOSX())
            {
                return(Marshal.PtrToStringAnsi(NativeOSXMethods.GetLoadLibraryErrorMessage()));
            }

            throw new PlatformNotSupportedException();
        }
Пример #15
0
        public static Type GetTypeOrTypeInfo(this object value)
        {
            if (!MiscHelpers.PlatformIsWindows())
            {
                return(value.GetType());
            }

            var       type     = value.GetType();
            IDispatch dispatch = null;

            Type      typeInfo      = null;
            TYPEKIND  typeInfoKind  = 0;
            TYPEFLAGS typeInfoFlags = 0;

            if (type.IsUnknownCOMObject())
            {
                // This appears to be a generic COM object with no specific type information.
                // Attempt to acquire COM type information via IDispatch or IProvideClassInfo.

                dispatch = value as IDispatch;
                if (dispatch != null)
                {
                    var tempTypeInfo = dispatch.GetTypeInfo();
                    if (tempTypeInfo != null)
                    {
                        typeInfo      = GetTypeForTypeInfo(tempTypeInfo);
                        typeInfoKind  = tempTypeInfo.GetKind();
                        typeInfoFlags = tempTypeInfo.GetFlags();
                    }
                }

                if (typeInfo == null)
                {
                    if (value is IProvideClassInfo provideClassInfo)
                    {
                        if (HResult.Succeeded(provideClassInfo.GetClassInfo(out var tempTypeInfo)))
                        {
                            typeInfo      = GetTypeForTypeInfo(tempTypeInfo);
                            typeInfoKind  = tempTypeInfo.GetKind();
                            typeInfoFlags = tempTypeInfo.GetFlags();
                        }
                    }
                }
            }

            if (typeInfo != null)
            {
                // If the COM type is a dispatch-only interface, use it. Such interfaces typically
                // aren't exposed via QueryInterface(), so there's no way to validate them anyway.

                if ((dispatch != null) && (typeInfoKind == TYPEKIND.TKIND_DISPATCH) && typeInfoFlags.HasFlag(TYPEFLAGS.TYPEFLAG_FDISPATCHABLE) && !typeInfoFlags.HasFlag(TYPEFLAGS.TYPEFLAG_FDUAL))
                {
                    return(typeInfo);
                }

                // COM type information acquired in this manner may not actually be valid for the
                // original object. In some cases the original object implements a base interface.

                if (typeInfo.IsInstanceOfType(value))
                {
                    return(typeInfo);
                }

                foreach (var interfaceType in typeInfo.GetInterfaces())
                {
                    if (interfaceType.IsInstanceOfType(value))
                    {
                        return(interfaceType);
                    }
                }
            }

            return(type);
        }