private static Guid GetGuidForTypeInfo(UnsafeNativeMethods.ITypeInfo typeInfo, StructCache structCache, int[] versions) { IntPtr zero = IntPtr.Zero; int typeAttr = typeInfo.GetTypeAttr(ref zero); if (!System.Windows.Forms.NativeMethods.Succeeded(typeAttr)) { throw new ExternalException(System.Windows.Forms.SR.GetString("TYPEINFOPROCESSORGetTypeAttrFailed", new object[] { typeAttr }), typeAttr); } Guid empty = Guid.Empty; System.Windows.Forms.NativeMethods.tagTYPEATTR data = null; try { if (structCache == null) { data = new System.Windows.Forms.NativeMethods.tagTYPEATTR(); } else { data = (System.Windows.Forms.NativeMethods.tagTYPEATTR) structCache.GetStruct(typeof(System.Windows.Forms.NativeMethods.tagTYPEATTR)); } UnsafeNativeMethods.PtrToStructure(zero, data); empty = data.guid; if (versions != null) { versions[0] = data.wMajorVerNum; versions[1] = data.wMinorVerNum; } } finally { typeInfo.ReleaseTypeAttr(zero); if ((structCache != null) && (data != null)) { structCache.ReleaseStruct(data); } } return empty; }
private static void ProcessVariables(UnsafeNativeMethods.ITypeInfo typeInfo, IDictionary propInfoList, int dispidToGet, int nameDispID, StructCache structCache) { IntPtr zero = IntPtr.Zero; int typeAttr = typeInfo.GetTypeAttr(ref zero); if (!System.Windows.Forms.NativeMethods.Succeeded(typeAttr) || (zero == IntPtr.Zero)) { throw new ExternalException(System.Windows.Forms.SR.GetString("TYPEINFOPROCESSORGetTypeAttrFailed", new object[] { typeAttr }), typeAttr); } System.Windows.Forms.NativeMethods.tagTYPEATTR data = (System.Windows.Forms.NativeMethods.tagTYPEATTR) structCache.GetStruct(typeof(System.Windows.Forms.NativeMethods.tagTYPEATTR)); UnsafeNativeMethods.PtrToStructure(zero, data); try { if (data != null) { System.Windows.Forms.NativeMethods.tagVARDESC gvardesc = (System.Windows.Forms.NativeMethods.tagVARDESC) structCache.GetStruct(typeof(System.Windows.Forms.NativeMethods.tagVARDESC)); for (int i = 0; i < data.cVars; i++) { IntPtr pVarDesc = IntPtr.Zero; if (System.Windows.Forms.NativeMethods.Succeeded(typeInfo.GetVarDesc(i, ref pVarDesc)) && (pVarDesc != IntPtr.Zero)) { UnsafeNativeMethods.PtrToStructure(pVarDesc, gvardesc); try { if ((gvardesc.varkind != 2) && ((dispidToGet == -1) || (gvardesc.memid == dispidToGet))) { PropInfo info = ProcessDataCore(typeInfo, propInfoList, gvardesc.memid, nameDispID, gvardesc.elemdescVar.tdesc, gvardesc.wVarFlags, structCache); if (info.ReadOnly != 1) { info.ReadOnly = 2; } } } finally { if (pVarDesc != IntPtr.Zero) { typeInfo.ReleaseVarDesc(pVarDesc); } } } } structCache.ReleaseStruct(gvardesc); } } finally { typeInfo.ReleaseTypeAttr(zero); structCache.ReleaseStruct(data); } }
private static void ProcessFunctions(UnsafeNativeMethods.ITypeInfo typeInfo, IDictionary propInfoList, int dispidToGet, int nameDispID, ref bool addAboutBox, StructCache structCache) { IntPtr zero = IntPtr.Zero; int typeAttr = typeInfo.GetTypeAttr(ref zero); if (!System.Windows.Forms.NativeMethods.Succeeded(typeAttr) || (zero == IntPtr.Zero)) { throw new ExternalException(System.Windows.Forms.SR.GetString("TYPEINFOPROCESSORGetTypeAttrFailed", new object[] { typeAttr }), typeAttr); } System.Windows.Forms.NativeMethods.tagTYPEATTR data = (System.Windows.Forms.NativeMethods.tagTYPEATTR) structCache.GetStruct(typeof(System.Windows.Forms.NativeMethods.tagTYPEATTR)); UnsafeNativeMethods.PtrToStructure(zero, data); try { if (data != null) { System.Windows.Forms.NativeMethods.tagFUNCDESC gfuncdesc = (System.Windows.Forms.NativeMethods.tagFUNCDESC) structCache.GetStruct(typeof(System.Windows.Forms.NativeMethods.tagFUNCDESC)); System.Windows.Forms.NativeMethods.tagELEMDESC structure = (System.Windows.Forms.NativeMethods.tagELEMDESC) structCache.GetStruct(typeof(System.Windows.Forms.NativeMethods.tagELEMDESC)); for (int i = 0; i < data.cFuncs; i++) { IntPtr pFuncDesc = IntPtr.Zero; if (System.Windows.Forms.NativeMethods.Succeeded(typeInfo.GetFuncDesc(i, ref pFuncDesc)) && (pFuncDesc != IntPtr.Zero)) { UnsafeNativeMethods.PtrToStructure(pFuncDesc, gfuncdesc); try { if ((gfuncdesc.invkind == 1) || ((dispidToGet != -1) && (gfuncdesc.memid != dispidToGet))) { if (gfuncdesc.memid == -552) { addAboutBox = true; } } else { System.Windows.Forms.NativeMethods.tagTYPEDESC tdesc; bool flag = gfuncdesc.invkind == 2; if (flag) { if (gfuncdesc.cParams != 0) { continue; } tdesc = gfuncdesc.elemdescFunc.tdesc; } else { if ((gfuncdesc.lprgelemdescParam == IntPtr.Zero) || (gfuncdesc.cParams != 1)) { continue; } Marshal.PtrToStructure(gfuncdesc.lprgelemdescParam, structure); tdesc = structure.tdesc; } PropInfo info = ProcessDataCore(typeInfo, propInfoList, gfuncdesc.memid, nameDispID, tdesc, gfuncdesc.wFuncFlags, structCache); if ((info != null) && !flag) { info.ReadOnly = 2; } } } finally { typeInfo.ReleaseFuncDesc(pFuncDesc); } } } structCache.ReleaseStruct(gfuncdesc); structCache.ReleaseStruct(structure); } } finally { typeInfo.ReleaseTypeAttr(zero); structCache.ReleaseStruct(data); } }
private static System.Type ProcessTypeInfoEnum(UnsafeNativeMethods.ITypeInfo enumTypeInfo, StructCache structCache) { if (enumTypeInfo != null) { try { IntPtr zero = IntPtr.Zero; int typeAttr = enumTypeInfo.GetTypeAttr(ref zero); if (!System.Windows.Forms.NativeMethods.Succeeded(typeAttr) || (zero == IntPtr.Zero)) { throw new ExternalException(System.Windows.Forms.SR.GetString("TYPEINFOPROCESSORGetTypeAttrFailed", new object[] { typeAttr }), typeAttr); } System.Windows.Forms.NativeMethods.tagTYPEATTR data = (System.Windows.Forms.NativeMethods.tagTYPEATTR) structCache.GetStruct(typeof(System.Windows.Forms.NativeMethods.tagTYPEATTR)); UnsafeNativeMethods.PtrToStructure(zero, data); if (zero == IntPtr.Zero) { return null; } try { int cVars = data.cVars; ArrayList list = new ArrayList(); ArrayList list2 = new ArrayList(); System.Windows.Forms.NativeMethods.tagVARDESC gvardesc = (System.Windows.Forms.NativeMethods.tagVARDESC) structCache.GetStruct(typeof(System.Windows.Forms.NativeMethods.tagVARDESC)); object objectForNativeVariant = null; string pBstrName = null; string pBstrDocString = null; enumTypeInfo.GetDocumentation(-1, ref pBstrName, ref pBstrDocString, null, null); for (int i = 0; i < cVars; i++) { IntPtr pVarDesc = IntPtr.Zero; if (System.Windows.Forms.NativeMethods.Succeeded(enumTypeInfo.GetVarDesc(i, ref pVarDesc)) && (pVarDesc != IntPtr.Zero)) { try { UnsafeNativeMethods.PtrToStructure(pVarDesc, gvardesc); if (((gvardesc != null) && (gvardesc.varkind == 2)) && (gvardesc.unionMember != IntPtr.Zero)) { str2 = (string) (pBstrDocString = null); objectForNativeVariant = null; if (System.Windows.Forms.NativeMethods.Succeeded(enumTypeInfo.GetDocumentation(gvardesc.memid, null, ref pBstrDocString, null, null))) { string str4; try { objectForNativeVariant = Marshal.GetObjectForNativeVariant(gvardesc.unionMember); } catch (Exception) { } list2.Add(objectForNativeVariant); if (pBstrDocString != null) { str4 = pBstrDocString; } else { str4 = str2; } list.Add(str4); } } } finally { if (pVarDesc != IntPtr.Zero) { enumTypeInfo.ReleaseVarDesc(pVarDesc); } } } } structCache.ReleaseStruct(gvardesc); if (list.Count > 0) { IntPtr iUnknownForObject = Marshal.GetIUnknownForObject(enumTypeInfo); try { pBstrName = iUnknownForObject.ToString() + "_" + pBstrName; if (builtEnums == null) { builtEnums = new Hashtable(); } else if (builtEnums.ContainsKey(pBstrName)) { return (System.Type) builtEnums[pBstrName]; } System.Type underlyingType = typeof(int); if ((list2.Count > 0) && (list2[0] != null)) { underlyingType = list2[0].GetType(); } EnumBuilder builder = ModuleBuilder.DefineEnum(pBstrName, TypeAttributes.Public, underlyingType); for (int j = 0; j < list.Count; j++) { builder.DefineLiteral((string) list[j], list2[j]); } System.Type type2 = builder.CreateType(); builtEnums[pBstrName] = type2; return type2; } finally { if (iUnknownForObject != IntPtr.Zero) { Marshal.Release(iUnknownForObject); } } } } finally { enumTypeInfo.ReleaseTypeAttr(zero); structCache.ReleaseStruct(data); } } catch { } } return null; }
private unsafe long GetTypeInfoVersion(UnsafeNativeMethods.ITypeInfo pTypeInfo) { long num3; IntPtr zero = IntPtr.Zero; if (!System.Windows.Forms.NativeMethods.Succeeded(pTypeInfo.GetTypeAttr(ref zero))) { return 0L; } try { System.Runtime.InteropServices.ComTypes.TYPEATTR typeattr; try { typeattr = *((System.Runtime.InteropServices.ComTypes.TYPEATTR*) zero); } catch { return 0L; } long num2 = 0L; int* numPtr = (int*) &num2; byte* numPtr2 = (byte*) &typeattr; numPtr[0] = *((int*) (numPtr2 + CountMemberOffset)); numPtr++; numPtr[0] = *((int*) (numPtr2 + VersionOffset)); num3 = num2; } finally { pTypeInfo.ReleaseTypeAttr(zero); } return num3; }