Exemplo n.º 1
0
        static void ReportCustomProperties(SolidEdgeFramework.PropertySets propertySets)
        {
            var properties = (SolidEdgeFramework.Properties)propertySets.Item("Custom");

            foreach (var property in properties.OfType <SolidEdgeFramework.Property>())
            {
                System.Runtime.InteropServices.VarEnum nativePropertyType = System.Runtime.InteropServices.VarEnum.VT_EMPTY;
                Type runtimePropertyType = null;

                object value = null;

                nativePropertyType = (System.Runtime.InteropServices.VarEnum)property.Type;

                // Accessing Value property may throw an exception...
                try
                {
                    value = property.get_Value();
                }
                catch (System.Exception ex)
                {
                    value = ex.Message;
                }

                if (value != null)
                {
                    runtimePropertyType = value.GetType();
                }

                Console.WriteLine("\t{0} = '{1}' ({2} | {3}).", property.Name, value, nativePropertyType, runtimePropertyType);
            }

            Console.WriteLine();
        }
Exemplo n.º 2
0
 public void TestErr_SetDatatypes02()
 {
     //Testing ---
     int[] arrHSrv = new int[1];
     System.Runtime.InteropServices.VarEnum[] arrVT = new System.Runtime.InteropServices.VarEnum[1];
     arrVT[0] = System.Runtime.InteropServices.VarEnum.VT_EMPTY;
     int[] arrErr = null;
     //Test Procedure Call
     bool b = group.SetDatatypes(arrHSrv, arrVT, out arrErr);
 }
Exemplo n.º 3
0
        /// <summary>
        /// Creates a representation for the parameter of a COM method
        /// </summary>
        internal ComParamDesc(ref ELEMDESC elemDesc, string name)
        {
            // Ensure _defaultValue is set to DBNull.Value regardless of whether or not the
            // default value is extracted from the parameter description.  Failure to do so
            // yields a runtime exception in the ToString() function.
            DefaultValue = DBNull.Value;

            if (!string.IsNullOrEmpty(name))
            {
                // This is a parameter, not a return value
                IsOut      = (elemDesc.desc.paramdesc.wParamFlags & PARAMFLAG.PARAMFLAG_FOUT) != 0;
                IsOptional = (elemDesc.desc.paramdesc.wParamFlags & PARAMFLAG.PARAMFLAG_FOPT) != 0;
                // TODO: The PARAMDESCEX struct has a memory issue that needs to be resolved.  For now, we ignore it.
                //_defaultValue = PARAMDESCEX.GetDefaultValue(ref elemDesc.desc.paramdesc);
            }

            _name = name;
            _vt   = (VarEnum)elemDesc.tdesc.vt;
            TYPEDESC typeDesc = elemDesc.tdesc;

            while (true)
            {
                if (_vt == VarEnum.VT_PTR)
                {
                    ByReference = true;
                }
                else if (_vt == VarEnum.VT_ARRAY)
                {
                    IsArray = true;
                }
                else
                {
                    break;
                }

                TYPEDESC childTypeDesc = (TYPEDESC)Marshal.PtrToStructure(typeDesc.lpValue, typeof(TYPEDESC));
                _vt      = (VarEnum)childTypeDesc.vt;
                typeDesc = childTypeDesc;
            }

            VarEnum vtWithoutByref = _vt;

            if ((_vt & VarEnum.VT_BYREF) != 0)
            {
                vtWithoutByref = (_vt & ~VarEnum.VT_BYREF);
                ByReference    = true;
            }

            ParameterType = VarEnumSelector.GetTypeForVarEnum(vtWithoutByref);
        }
Exemplo n.º 4
0
        public void TestVarEnumToString01()
        {
            System.Runtime.InteropServices.VarEnum varEnum = (System.Runtime.InteropServices.VarEnum)DUMMY_VARIANT.VT_ILLEGAL;
            //Test Procedure Call
            string str = DUMMY_VARIANT.VarEnumToString(varEnum);

            //Post Condition Check
            Assert.AreEqual("VT_ILLEGAL", str);

            //test
            varEnum = (System.Runtime.InteropServices.VarEnum)DUMMY_VARIANT.VT_ARRAY;
            //Test Procedure Call
            str = DUMMY_VARIANT.VarEnumToString(varEnum);
            //Post Condition Check
            Assert.AreEqual("VT_ARRAY | VT_EMPTY", str);

            //test
            varEnum = (System.Runtime.InteropServices.VarEnum)DUMMY_VARIANT.VT_BYREF;
            //Test Procedure Call
            str = DUMMY_VARIANT.VarEnumToString(varEnum);
            //Post Condition Check
            Assert.AreEqual("VT_BYREF | VT_EMPTY", str);

            //test
            varEnum = (System.Runtime.InteropServices.VarEnum)DUMMY_VARIANT.VT_VECTOR;
            //Test Procedure Call
            str = DUMMY_VARIANT.VarEnumToString(varEnum);
            //Post Condition Check
            Assert.AreEqual("VT_VECTOR | VT_EMPTY", str);

            //test
            varEnum = (System.Runtime.InteropServices.VarEnum)DUMMY_VARIANT.VT_TYPEMASK;
            //Test Procedure Call
            str = DUMMY_VARIANT.VarEnumToString(varEnum);


            //test
            varEnum = System.Runtime.InteropServices.VarEnum.VT_I4;
            //Test Procedure Call
            str = DUMMY_VARIANT.VarEnumToString(varEnum);
            //Post Condition Check
            Assert.AreEqual("VT_I4", str);
        }
Exemplo n.º 5
0
        /// <summary>
        /// Creates a representation for the paramter of a COM method
        /// </summary>
        internal ComParamDesc(ref ELEMDESC elemDesc, string name)
        {
            // Ensure _defaultValue is set to DBNull.Value regardless of whether or not the
            // default value is extracted from the parameter description.  Failure to do so
            // yields a runtime exception in the ToString() function.
            _defaultValue = DBNull.Value;

            if (!String.IsNullOrEmpty(name)) {
                // This is a parameter, not a return value
                this._isOut = (elemDesc.desc.paramdesc.wParamFlags & PARAMFLAG.PARAMFLAG_FOUT) != 0;
                this._isOpt = (elemDesc.desc.paramdesc.wParamFlags & PARAMFLAG.PARAMFLAG_FOPT) != 0;
                // TODO: The PARAMDESCEX struct has a memory issue that needs to be resolved.  For now, we ignore it.
                //_defaultValue = PARAMDESCEX.GetDefaultValue(ref elemDesc.desc.paramdesc);
            }

            _name = name;
            _vt = (VarEnum)elemDesc.tdesc.vt;
            TYPEDESC typeDesc = elemDesc.tdesc;
            while (true) {
                if (_vt == VarEnum.VT_PTR) {
                    this._byRef = true;
                } else if (_vt == VarEnum.VT_ARRAY) {
                    this._isArray = true;
                } else {
                    break;
                }

                TYPEDESC childTypeDesc = (TYPEDESC)Marshal.PtrToStructure(typeDesc.lpValue, typeof(TYPEDESC));
                _vt = (VarEnum)childTypeDesc.vt;
                typeDesc = childTypeDesc;
            }

            VarEnum vtWithoutByref = _vt;
            if ((_vt & VarEnum.VT_BYREF) != 0) {
                vtWithoutByref = (_vt & ~VarEnum.VT_BYREF);
                _byRef = true;
            }

            _type = GetTypeForVarEnum(vtWithoutByref);
        }
Exemplo n.º 6
0
        static void Main(string[] args)
        {
            SolidEdgeFramework.Application application = null;

            try
            {
                // Register with OLE to handle concurrency issues on the current thread.
                SolidEdgeCommunity.OleMessageFilter.Register();

                // Connect to or start Solid Edge.
                application = SolidEdgeCommunity.SolidEdgeUtils.Connect(true, true);

                // Get a reference to the active assembly document.
                var document = application.GetActiveDocument <SolidEdgeAssembly.AssemblyDocument>(false);

                if (document != null)
                {
                    var propertySets = (SolidEdgeFramework.PropertySets)document.Properties;

                    foreach (var properties in propertySets.OfType <SolidEdgeFramework.Properties>())
                    {
                        Console.WriteLine("PropertSet '{0}'.", properties.Name);

                        foreach (var property in properties.OfType <SolidEdgeFramework.Property>())
                        {
                            System.Runtime.InteropServices.VarEnum nativePropertyType = System.Runtime.InteropServices.VarEnum.VT_EMPTY;
                            Type runtimePropertyType = null;

                            object value = null;

                            nativePropertyType = (System.Runtime.InteropServices.VarEnum)property.Type;

                            // Accessing Value property may throw an exception...
                            try
                            {
                                value = property.get_Value();
                            }
                            catch (System.Exception ex)
                            {
                                value = ex.Message;
                            }

                            if (value != null)
                            {
                                runtimePropertyType = value.GetType();
                            }

                            Console.WriteLine("\t{0} = '{1}' ({2} | {3}).", property.Name, value, nativePropertyType, runtimePropertyType);
                        }

                        Console.WriteLine();
                    }
                }
                else
                {
                    throw new System.Exception("No active document.");
                }
            }
            catch (System.Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
            finally
            {
                SolidEdgeCommunity.OleMessageFilter.Unregister();
            }
        }
Exemplo n.º 7
0
        //internal struct PARAMDESCEX {
        //    private ulong _cByte;
        //    private Variant _varDefaultValue;
        //    internal void Dummy() {
        //        _cByte = 0;
        //        throw Error.MethodShouldNotBeCalled();
        //    }
        //    internal static object GetDefaultValue(ref PARAMDESC paramdesc) {
        //        if ((paramdesc.wParamFlags & PARAMFLAG.PARAMFLAG_FHASDEFAULT) == 0) {
        //            return DBNull.Value;
        //        }
        //        PARAMDESCEX varValue = (PARAMDESCEX)Marshal.PtrToStructure(paramdesc.lpVarValue, typeof(PARAMDESCEX));
        //        if (varValue._cByte != (ulong)(Marshal.SizeOf((typeof(PARAMDESCEX))))) {
        //            throw Error.DefaultValueCannotBeRead();
        //        }
        //        return varValue._varDefaultValue.ToObject();
        //    }
        //}
        private static Type GetTypeForVarEnum(VarEnum vt)
        {
            Type type;

            switch (vt) {
                // VarEnums which can be used in VARIANTs, but which cannot occur in a TYPEDESC
                case VarEnum.VT_EMPTY:
                case VarEnum.VT_NULL:
                case VarEnum.VT_RECORD:
                    throw new InvalidOperationException(string.Format("Unexpected VarEnum {0}.", vt));

                // VarEnums which are not used in VARIANTs, but which can occur in a TYPEDESC
                case VarEnum.VT_VOID:
                    type = null;
                    break;

            #if DISABLE // TODO: WTypes.h indicates that these cannot be used in VARIANTs, but Type.InvokeMember seems to allow it
                case VarEnum.VT_I8:
                case VarEnum.UI8:
            #endif
                case VarEnum.VT_HRESULT:
                    type = typeof(int);
                    break;

                case ((VarEnum)37): // VT_INT_PTR:
                case VarEnum.VT_PTR:
                    type = typeof(IntPtr);
                    break;

                case ((VarEnum)38): // VT_UINT_PTR:
                    type = typeof(UIntPtr);
                    break;

                case VarEnum.VT_SAFEARRAY:
                case VarEnum.VT_CARRAY:
                    type = typeof(Array);
                    break;

                case VarEnum.VT_LPSTR:
                case VarEnum.VT_LPWSTR:
                    type = typeof(string);
                    break;

                case VarEnum.VT_USERDEFINED:
                    type = typeof(object);
                    break;

                // For VarEnums that can be used in VARIANTs and well as TYPEDESCs, just use VarEnumSelector
                default:
                    type = VarEnumSelector.GetManagedMarshalType(vt);
                    break;
            }

            return type;
        }