public static IntPtr HeapCreate(uint options, UIntPtr initialSize, UIntPtr maximumSize) { if (MiscHelpers.PlatformIsWindows()) { return(NativeWindowsMethods.HeapCreate(options, initialSize, maximumSize)); } throw new PlatformNotSupportedException(); }
public static IntPtr HeapAlloc(IntPtr hHeap, uint flags, UIntPtr size) { if (MiscHelpers.PlatformIsWindows()) { return(NativeWindowsMethods.HeapAlloc(hHeap, flags, size)); } throw new PlatformNotSupportedException(); }
public static uint ProgIDFromCLSID(ref Guid clsid, out string progID) { if (MiscHelpers.PlatformIsWindows()) { return(NativeWindowsMethods.ProgIDFromCLSID(ref clsid, out progID)); } throw new PlatformNotSupportedException(); }
public static uint VariantClear(IntPtr pVariant) { if (MiscHelpers.PlatformIsWindows()) { return(NativeWindowsMethods.VariantClear(pVariant)); } throw new PlatformNotSupportedException(); }
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(); }
public static bool FreeLibrary(IntPtr hLibrary) { if (MiscHelpers.PlatformIsWindows()) { return(NativeWindowsMethods.FreeLibrary(hLibrary)); } throw new PlatformNotSupportedException(); }
public static uint CLSIDFromProgID(string progID, out Guid clsid) { if (MiscHelpers.PlatformIsWindows()) { return(NativeWindowsMethods.CLSIDFromProgID(progID, out clsid)); } throw new PlatformNotSupportedException(); }
public static bool HeapDestroy(IntPtr hHeap) { if (MiscHelpers.PlatformIsWindows()) { return(NativeWindowsMethods.HeapDestroy(hHeap)); } throw new PlatformNotSupportedException(); }
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(); }
public static bool HeapFree(IntPtr hHeap, uint flags, IntPtr pBlock) { if (MiscHelpers.PlatformIsWindows()) { return(NativeWindowsMethods.HeapFree(hHeap, flags, pBlock)); } throw new PlatformNotSupportedException(); }
public static IntPtr LoadLibraryW(string path) { if (MiscHelpers.PlatformIsWindows()) { return(NativeWindowsMethods.LoadLibraryW(path)); } throw new PlatformNotSupportedException(); }
public static void VariantInit(IntPtr pVariant) { if (MiscHelpers.PlatformIsWindows()) { NativeWindowsMethods.VariantInit(pVariant); } else { throw new PlatformNotSupportedException(); } }
public static void GetNativeSystemInfo(out SystemInfo info) { if (MiscHelpers.PlatformIsWindows()) { NativeWindowsMethods.GetNativeSystemInfo(out info); } else { throw new PlatformNotSupportedException(); } }
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(); }
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); }