|
| 1 | +using System; |
| 2 | +using System.Runtime.InteropServices; |
| 3 | + |
| 4 | +namespace Rubberduck.VBEditor.Variants |
| 5 | +{ |
| 6 | + public enum VARENUM |
| 7 | + { |
| 8 | + VT_EMPTY = 0x0000, |
| 9 | + VT_NULL = 0x0001, |
| 10 | + VT_I2 = 0x0002, |
| 11 | + VT_I4 = 0x0003, |
| 12 | + VT_R4 = 0x0004, |
| 13 | + VT_R8 = 0x0005, |
| 14 | + VT_CY = 0x0006, |
| 15 | + VT_DATE = 0x0007, |
| 16 | + VT_BSTR = 0x0008, |
| 17 | + VT_DISPATCH = 0x0009, |
| 18 | + VT_ERROR = 0x000A, |
| 19 | + VT_BOOL = 0x000B, |
| 20 | + VT_VARIANT = 0x000C, |
| 21 | + VT_UNKNOWN = 0x000D, |
| 22 | + VT_DECIMAL = 0x000E, |
| 23 | + VT_I1 = 0x0010, |
| 24 | + VT_UI1 = 0x0011, |
| 25 | + VT_UI2 = 0x0012, |
| 26 | + VT_UI4 = 0x0013, |
| 27 | + VT_I8 = 0x0014, |
| 28 | + VT_UI8 = 0x0015, |
| 29 | + VT_INT = 0x0016, |
| 30 | + VT_UINT = 0x0017, |
| 31 | + VT_VOID = 0x0018, |
| 32 | + VT_HRESULT = 0x0019, |
| 33 | + VT_PTR = 0x001A, |
| 34 | + VT_SAFEARRAY = 0x001B, |
| 35 | + VT_CARRAY = 0x001C, |
| 36 | + VT_USERDEFINED = 0x001D, |
| 37 | + VT_LPSTR = 0x001E, |
| 38 | + VT_LPWSTR = 0x001F, |
| 39 | + VT_RECORD = 0x0024, |
| 40 | + VT_INT_PTR = 0x0025, |
| 41 | + VT_UINT_PTR = 0x0026, |
| 42 | + VT_ARRAY = 0x2000, |
| 43 | + VT_BYREF = 0x4000 |
| 44 | + } |
| 45 | + |
| 46 | + [Flags] |
| 47 | + public enum VariantConversionFlags : ushort |
| 48 | + { |
| 49 | + NO_FLAGS = 0x00, |
| 50 | + VARIANT_NOVALUEPROP = 0x01, //Prevents the function from attempting to coerce an object to a fundamental type by getting the Value property. Applications should set this flag only if necessary, because it makes their behavior inconsistent with other applications. |
| 51 | + VARIANT_ALPHABOOL = 0x02, //Converts a VT_BOOL value to a string containing either "True" or "False". |
| 52 | + VARIANT_NOUSEROVERRIDE = 0x04, //For conversions to or from VT_BSTR, passes LOCALE_NOUSEROVERRIDE to the core coercion routines. |
| 53 | + VARIANT_LOCALBOOL = 0x08 //For conversions from VT_BOOL to VT_BSTR and back, uses the language specified by the locale in use on the local computer. |
| 54 | + } |
| 55 | + |
| 56 | + [Flags] |
| 57 | + public enum VariantComparisonFlags : ulong |
| 58 | + { |
| 59 | + NO_FLAGS = 0x00, |
| 60 | + NORM_IGNORECASE = 0x00000001, //Ignore case. |
| 61 | + NORM_IGNORENONSPACE = 0x00000002, //Ignore nonspace characters. |
| 62 | + NORM_IGNORESYMBOLS = 0x00000004, //Ignore symbols. |
| 63 | + NORM_IGNOREWIDTH = 0x00000008, //Ignore string width. |
| 64 | + NORM_IGNOREKANATYPE = 0x00000040, //Ignore Kana type. |
| 65 | + NORM_IGNOREKASHIDA = 0x00040000 //Ignore Arabic kashida characters. |
| 66 | + } |
| 67 | + |
| 68 | + public enum VariantComparisonResults : int |
| 69 | + { |
| 70 | + VARCMP_LT = 0, //pvarLeft is less than pvarRight. |
| 71 | + VARCMP_EQ = 1, //The parameters are equal. |
| 72 | + VARCMP_GT = 2, //pvarLeft is greater than pvarRight. |
| 73 | + VARCMP_NULL = 3 //Either expression is NULL. |
| 74 | + } |
| 75 | + |
| 76 | + public static class HResult |
| 77 | + { |
| 78 | + internal static bool Succeeded(int hr) => hr >= 0; |
| 79 | + internal static bool Failed(int hr) => hr < 0; |
| 80 | + } |
| 81 | + |
| 82 | + internal static class VariantNativeMethods |
| 83 | + { |
| 84 | + private const string dllName = "oleaut32.dll"; |
| 85 | + |
| 86 | + // HRESULT VariantChangeType( |
| 87 | + // VARIANTARG *pvargDest, |
| 88 | + // const VARIANTARG *pvarSrc, |
| 89 | + // USHORT wFlags, |
| 90 | + // VARTYPE vt |
| 91 | + // ); |
| 92 | + [DllImport(dllName, EntryPoint = "VariantChangeType", CharSet = CharSet.Auto, SetLastError = true, PreserveSig = true)] |
| 93 | + internal static extern int VariantChangeType(ref object pvargDest, ref object pvarSrc, VariantConversionFlags wFlags, VARENUM vt); |
| 94 | + |
| 95 | + // HRESULT VariantChangeTypeEx( |
| 96 | + // VARIANTARG *pvargDest, |
| 97 | + // const VARIANTARG *pvarSrc, |
| 98 | + // LCID lcid, |
| 99 | + // USHORT wFlags, |
| 100 | + // VARTYPE vt |
| 101 | + // ); |
| 102 | + [DllImport(dllName, EntryPoint = "VariantChangeTypeEx", CharSet = CharSet.Auto, SetLastError = true, PreserveSig = true)] |
| 103 | + internal static extern int VariantChangeTypeEx(ref object pvargDest, ref object pvarSrc, int lcid, VariantConversionFlags wFlags, VARENUM vt); |
| 104 | + |
| 105 | + // HRESULT VarCmp( |
| 106 | + // LPVARIANT pvarLeft, |
| 107 | + // LPVARIANT pvarRight, |
| 108 | + // LCID lcid, |
| 109 | + // ULONG dwFlags |
| 110 | + // ); |
| 111 | + [DllImport(dllName, EntryPoint = "VarCmp", CharSet = CharSet.Auto, SetLastError = true, PreserveSig = true)] |
| 112 | + internal static extern int VarCmp(ref object pvarLeft, ref object pvarRight, int lcid, ulong dwFlags); |
| 113 | + } |
| 114 | +} |
0 commit comments