예제 #1
0
        public static string VarEnumToString(VarEnum vevt)
        {
            string strvt   = "";
            short  vtshort = (short)vevt;

            if (vtshort == VT_ILLEGAL)
            {
                return("VT_ILLEGAL");
            }

            if ((vtshort & VT_ARRAY) != 0)
            {
                strvt += "VT_ARRAY | ";
            }

            if ((vtshort & VT_BYREF) != 0)
            {
                strvt += "VT_BYREF | ";
            }

            if ((vtshort & VT_VECTOR) != 0)
            {
                strvt += "VT_VECTOR | ";
            }

            VarEnum vtbase = (VarEnum)(vtshort & VT_TYPEMASK);

            strvt += vtbase.ToString();
            return(strvt);
        }
예제 #2
0
        public static string VarEnumToString(VarEnum vevt)
        {
            string str = "";
            short  num = (short)vevt;

            if (num == VT_ILLEGAL)
            {
                return("VT_ILLEGAL");
            }
            if ((num & VT_ARRAY) != 0)
            {
                str = str + "VT_ARRAY | ";
            }
            if ((num & VT_BYREF) != 0)
            {
                str = str + "VT_BYREF | ";
            }
            if ((num & VT_VECTOR) != 0)
            {
                str = str + "VT_VECTOR | ";
            }
            VarEnum enum2 = ((VarEnum)num) & ((VarEnum)VT_TYPEMASK);

            return(str + enum2.ToString());
        }
예제 #3
0
        public static string VarEnumToString(VarEnum p_VT)
        {
            string l_StrVT   = "";
            short  l_VTShort = (short)p_VT;

            if (l_VTShort == VT_ILLEGAL)
            {
                return("VT_ILLEGAL");
            }
            if ((l_VTShort & VT_ARRAY) != 0)
            {
                l_StrVT += "VT_ARRAY | ";
            }
            if ((l_VTShort & VT_BYREF) != 0)
            {
                l_StrVT += "VT_BYREF | ";
            }
            if ((l_VTShort & VT_VECTOR) != 0)
            {
                l_StrVT += "VT_VECTOR | ";
            }

            VarEnum l_VTBase = (VarEnum)(l_VTShort & VT_TYPEMASK);

            l_StrVT += l_VTBase.ToString();

            return(l_StrVT);
        }
예제 #4
0
        public void GetItemProperties(string tagName)
        {
            int count = 4;

            List <int> propIds = new List <int>();

            propIds.Add(0);
            propIds.Add(1);
            propIds.Add(2);
            propIds.Add(3);
            propIds.Add(4);

            Array PropertyIDs = propIds.ToArray();
            Array PropertyValues;
            Array Errors;

            try{
                mServer.GetItemProperties(tagName, count, ref PropertyIDs, out PropertyValues, out Errors);
                if ((count == 0) || (count > 10000))
                {
                    return;
                }

                for (int i = 1; i <= count; i++)
                {
                    if (i == 1)
                    {
                        VarEnum foo = (VarEnum)VarEnum.ToObject(typeof(VarEnum), PropertyValues.GetValue(i));

                        var text = foo.ToString();                      // "Clubs"
                        // these methods are clunkier but run 25% faster on my machine
                        var text2 = Enum.GetName(typeof(VarEnum), foo); // "Clubs"
                        //var text3 = typeof(VarEnum).GetEnumName(foo); // "Clubs"
                    }

                    Console.WriteLine("in GetItemProperties, tagName is : " + tagName + ": DataType is: " + PropertyValues.GetValue(i).GetType() + ": " + PropertyIDs.GetValue(i) + ", " + PropertyValues.GetValue(i).ToString() + ", " + Errors.GetValue(i));
                }
            } catch (Exception ex)
            {
            }
        }
예제 #5
0
        /// <summary>
        /// Initializes the array as a <see cref="UnmanagedType.SafeArray"/>.
        /// </summary>
        private void InitializeAsSafeArray(NativeTypeDesc desc)
        {
            this.arrayKind = ArrayKind.SafeArray;

            Type array_mng_type = desc.Type;

            VarEnum sub_type = VarEnum.VT_EMPTY;

            if (desc.MarshalAs != null && desc.MarshalAs.SafeArraySubType != VarEnum.VT_EMPTY)
            {
                sub_type = desc.MarshalAs.SafeArraySubType;
            }
            else
            {
                // the unmanaged type may also be specified statically using one of the wrapper classes
                if (array_mng_type == typeof(UnknownWrapper[]))
                {
                    array_mng_type = typeof(object[]);
                    sub_type       = VarEnum.VT_UNKNOWN;
                }
                else if (array_mng_type == typeof(DispatchWrapper[]))
                {
                    array_mng_type = typeof(object[]);
                    sub_type       = VarEnum.VT_DISPATCH;
                }
                else if (array_mng_type == typeof(ErrorWrapper[]))
                {
                    array_mng_type = typeof(int[]);
                    sub_type       = VarEnum.VT_ERROR;
                }
                else if (array_mng_type == typeof(CurrencyWrapper[]))
                {
                    array_mng_type = typeof(Decimal[]);
                    sub_type       = VarEnum.VT_CY;
                }
                else if (array_mng_type == typeof(BStrWrapper[]))
                {
                    array_mng_type = typeof(string[]);
                    sub_type       = VarEnum.VT_BSTR;
                }
            }

            // convert the SafeArraySubType to UnmanagedType
            UnmanagedType element_unmng_type = Utility.VarEnumToUnmanagedType(sub_type);

            // determine the element type
            // (this will have no effect on the C++ signature but we will check it and add it to log)
            this.elementType = NativeType.FromClrArrayElement(
                array_mng_type,
                element_unmng_type,
                (desc.Flags & ~MarshalFlags.ByRefParam) | MarshalFlags.ComInterop);

            if (sub_type == VarEnum.VT_EMPTY)
            {
                sub_type = Utility.TypeToVarEnum(array_mng_type.GetElementType());
            }

            if (!elementType.IsInvalid)
            {
                if (array_mng_type != typeof(System.Array) || sub_type != VarEnum.VT_EMPTY)
                {
                    // log the element native type
                    Log.Add(Errors.INFO_SafeArrayWillMarshalAs, sub_type.ToString());
                }
            }

            // also include the *Wrapper hint if applicable
            if (desc.Type == typeof(object[]) && (sub_type == VarEnum.VT_EMPTY || sub_type == VarEnum.VT_VARIANT))
            {
                Log.Add(Errors.INFO_SafeArrayOfVariantsWrapperUse);
            }

            ExplainMemoryManagement(desc, Resources._SafeArray);
        }
예제 #6
0
        public void SetValue(string str, VarEnum t)
        {
            this.type = t;
            try
            {
                switch (t)
                {
                case VarEnum.VT_EMPTY:
                    this.value = 0;
                    break;

                case VarEnum.VT_BOOL:
                    value = Convert.ToBoolean(str);
                    break;

                case VarEnum.VT_UI1:
                    value = Convert.ToByte(str);
                    break;

                case VarEnum.VT_I1:
                    value = Convert.ToChar(str);
                    break;

                case VarEnum.VT_I2:
                    value = Convert.ToInt16(str);
                    break;

                case VarEnum.VT_UI4:
                    value = Convert.ToInt32(str);
                    break;

                case VarEnum.VT_I4:
                    value = Convert.ToInt32(str);
                    break;

                case VarEnum.VT_DECIMAL:
                    value = Convert.ToDecimal(str);
                    break;

                case VarEnum.VT_R4:
                    value = Convert.ToSingle(str);
                    break;

                case VarEnum.VT_R8:
                    value = Convert.ToDouble(str);
                    break;

                //if variant=
                case VarEnum.VT_VARIANT:
                    value = new MyVariant(str, t);
                    break;

                case VarEnum.VT_BSTR:
                    str   = str.Replace("\"", "");
                    str   = str.Replace("\'", "");
                    value = str;
                    break;

                case VarEnum.VT_UI1 | VarEnum.VT_ARRAY:
                    value = null;
                    break;

                case VarEnum.VT_BSTR | VarEnum.VT_ARRAY:
                    value = null;
                    break;

                case VarEnum.VT_I4 | VarEnum.VT_ARRAY:
                    value = null;
                    break;

                case VarEnum.VT_BOOL | VarEnum.VT_ARRAY:
                    value = null;
                    break;

                case VarEnum.VT_VARIANT | VarEnum.VT_ARRAY:
                    value = null;
                    break;

                default:
                {
                    this.value = null;
                    throw new Exception("Unknow type: " + t.ToString());
                }
                }
            }
            catch (Exception e)
            {
                throw new Exception("Bad type conversion: (" + e.Message + ")");
            }
        }
        private unsafe object GetValue(VarEnum vt)
        {
            object value = null;

            switch ((VarEnum)vt)
            {
            case VarEnum.VT_EMPTY:
            case VarEnum.VT_NULL:
                value = null;
                break;

            case VarEnum.VT_I1:
                value = cVal;
                break;

            case VarEnum.VT_UI1:
                value = bVal;
                break;

            case VarEnum.VT_I2:
                value = iVal;
                break;

            case VarEnum.VT_UI2:
                value = uiVal;
                break;

            case VarEnum.VT_I4:
                value = lVal;
                break;

            case VarEnum.VT_UI4:
                value = ulVal;
                break;

            case VarEnum.VT_I8:
                value = hVal;
                break;

            case VarEnum.VT_UI8:
                value = uhVal;
                break;

            case VarEnum.VT_R4:
                value = fltVal;
                break;

            case VarEnum.VT_R8:
                value = dblVal;
                break;

            case VarEnum.VT_INT:
                value = intVal;
                break;

            case VarEnum.VT_UINT:
                value = uintVal;
                break;

            case VarEnum.VT_ERROR:
                value = scode;
                break;

            case VarEnum.VT_BOOL:
                value = boolVal;
                break;

            case VarEnum.VT_CY:
                value = decimal.FromOACurrency(hVal);
                break;

            case VarEnum.VT_DATE:
                value = DateTime.FromOADate(dblVal);
                break;

            case VarEnum.VT_FILETIME:
                value = DateTime.FromFileTime(hVal);
                break;

            case VarEnum.VT_BSTR:
                value = Marshal.PtrToStringBSTR(ptr);
                break;

            case VarEnum.VT_LPSTR:
                value = Marshal.PtrToStringAnsi(ptr);
                break;

            case VarEnum.VT_LPWSTR:
                value = Marshal.PtrToStringUni(ptr);
                break;

            case VarEnum.VT_UNKNOWN:
                value = Marshal.GetObjectForIUnknown(ptr);
                break;

            case VarEnum.VT_DISPATCH:
                value = Marshal.GetObjectForIUnknown(ptr);
                break;

            case VarEnum.VT_VECTOR | VarEnum.VT_I1:
                value = GetVectorData <sbyte>();
                break;

            case VarEnum.VT_VECTOR | VarEnum.VT_UI1:
                value = GetVectorData <byte>();
                break;

            case VarEnum.VT_VECTOR | VarEnum.VT_I2:
                value = GetVectorData <short>();
                break;

            case VarEnum.VT_VECTOR | VarEnum.VT_UI2:
                value = GetVectorData <ushort>();
                break;

            case VarEnum.VT_VECTOR | VarEnum.VT_I4:
                value = GetVectorData <int>();
                break;

            case VarEnum.VT_VECTOR | VarEnum.VT_UI4:
                value = GetVectorData <uint>();
                break;

            case VarEnum.VT_VECTOR | VarEnum.VT_I8:
                value = GetVectorData <long>();
                break;

            case VarEnum.VT_VECTOR | VarEnum.VT_UI8:
                value = GetVectorData <ulong>();
                break;

            case VarEnum.VT_VECTOR | VarEnum.VT_R4:
                value = GetVectorData <float>();
                break;

            case VarEnum.VT_VECTOR | VarEnum.VT_R8:
                value = GetVectorData <double>();
                break;

            case VarEnum.VT_VECTOR | VarEnum.VT_INT:
                value = GetVectorData <int>();
                break;

            case VarEnum.VT_VECTOR | VarEnum.VT_UINT:
                value = GetVectorData <uint>();
                break;

            case VarEnum.VT_VECTOR | VarEnum.VT_BOOL:
                value = GetVectorData <bool>();
                break;

            case VarEnum.VT_CLSID:
                value = Marshal.PtrToStructure(ptr, typeof(Guid));
                break;

            default:
                throw new NotSupportedException("The type of this variable is not supported ('" + vt.ToString() + "')");
            }

            return(value);
        }
예제 #8
0
        public static string VarEnumToString(VarEnum type)
        {
            string ret = "";

            switch (type)
            {
            case VarEnum.VT_EMPTY:
                ret = "VT_EMPTY";
                break;

            case VarEnum.VT_BOOL:
                ret = "BOOL";
                break;

            case VarEnum.VT_UI1:
                ret = "BYTE";
                break;

            case VarEnum.VT_I1:
                ret = "CHAR";
                break;

            case VarEnum.VT_I2:
                ret = "INT";
                break;

            case VarEnum.VT_UI4:
                ret = "INT";
                break;

            case VarEnum.VT_I4:
                ret = "INT";
                break;

            case VarEnum.VT_DECIMAL:
                ret = "DECIMAL";
                break;

            case VarEnum.VT_R4:
                ret = "FLOAT";
                break;

            case VarEnum.VT_R8:
                ret = "DOUBLE";
                break;

            case VarEnum.VT_BSTR:
                ret = "STRING";
                break;

            case VarEnum.VT_VARIANT:
                ret = "VARIANT";
                break;

            case VarEnum.VT_UI1 | VarEnum.VT_ARRAY:
                ret = "BYTE [ ]";
                break;

            case VarEnum.VT_BSTR | VarEnum.VT_ARRAY:
                ret = "STRING [ ]";
                break;

            case VarEnum.VT_I4 | VarEnum.VT_ARRAY:
                ret = "INT [ ]";
                break;

            case VarEnum.VT_BOOL | VarEnum.VT_ARRAY:
                ret = "BOOL [ ]";
                break;

            case VarEnum.VT_VARIANT | VarEnum.VT_ARRAY:
                ret = "VARIANT [ ]";
                break;

            case VarEnum.VT_UNKNOWN:
                ret = "Unknow";
                break;

            default:
                ret = "Unknow (" + type.ToString() + ")";
                break;
            }
            return(ret);
        }
예제 #9
0
        protected string GetComType(VarEnum varEnum)
        {
            if ((varEnum & VarEnum.VT_BYREF) == VarEnum.VT_BYREF)
            {
                return(GetComType(varEnum & ~VarEnum.VT_BYREF) + "&");
            }
            else if ((varEnum & VarEnum.VT_ARRAY) == VarEnum.VT_ARRAY)
            {
                return(ComBrowserSettings.GetKeyword(VarEnum.VT_ARRAY) + "("
                       + GetComType(varEnum & ~VarEnum.VT_ARRAY) + ")");
            }
            else if ((varEnum & VarEnum.VT_VECTOR) == VarEnum.VT_VECTOR)
            {
                return(GetComType(varEnum & ~VarEnum.VT_VECTOR) + "[]");
            }

            switch (varEnum)
            {
            case VarEnum.VT_BOOL:
            case VarEnum.VT_UI1:
            case VarEnum.VT_UI2:
            case VarEnum.VT_UINT:
            case VarEnum.VT_UI4:
            case VarEnum.VT_UI8:
            case VarEnum.VT_I1:
            case VarEnum.VT_I2:
            case VarEnum.VT_I4:
            case VarEnum.VT_INT:
            case VarEnum.VT_I8:
            case VarEnum.VT_R4:
            case VarEnum.VT_R8:
            case VarEnum.VT_BSTR:
            case VarEnum.VT_VOID:
            case VarEnum.VT_HRESULT:
            case VarEnum.VT_UNKNOWN:
            case VarEnum.VT_DISPATCH:
            case VarEnum.VT_CLSID:
            case VarEnum.VT_CY:
            case VarEnum.VT_DATE:
            case VarEnum.VT_DECIMAL:
            case VarEnum.VT_FILETIME:
            case VarEnum.VT_VARIANT:
            case VarEnum.VT_ERROR:
            case VarEnum.VT_LPSTR:
            case VarEnum.VT_LPWSTR:
                return(ComBrowserSettings.GetKeyword(varEnum));

            case VarEnum.VT_EMPTY:
            case VarEnum.VT_NULL:
            case VarEnum.VT_USERDEFINED:
            case VarEnum.VT_CARRAY:
            case VarEnum.VT_CF:
            case VarEnum.VT_RECORD:
            case VarEnum.VT_BLOB:
            case VarEnum.VT_BLOB_OBJECT:
            case VarEnum.VT_PTR:
            case VarEnum.VT_SAFEARRAY:
                Debug.Fail("GetComType(VarEnum) called for " + varEnum.ToString());
                return(varEnum.ToString());

            default:
                Debug.Fail("Unexpected value of varEnum: " + varEnum.ToString());
                return("<VarEnum type '" + varEnum.ToString() + "'>");
            }
        }