/// <include file='doc\AxParameterData.uex' path='docs/doc[@for="AxParameterData.AxParameterData3"]/*' /> /// <devdoc> /// <para>[To be supplied.]</para> /// </devdoc> public AxParameterData(ParameterInfo info, bool ignoreByRefs) { Name = info.Name; this.type = info.ParameterType; this.typeName = AxWrapperGen.MapTypeName(info.ParameterType); this.isByRef = info.ParameterType.IsByRef && !ignoreByRefs; this.isIn = info.IsIn && !ignoreByRefs; this.isOut = info.IsOut && !this.isIn && !ignoreByRefs; this.isOptional = info.IsOptional; }
public AxParameterData(System.Reflection.ParameterInfo info, bool ignoreByRefs) { this.paramInfo = info; this.Name = info.Name; this.type = info.ParameterType; this.typeName = AxWrapperGen.MapTypeName(info.ParameterType); this.isByRef = info.ParameterType.IsByRef && !ignoreByRefs; this.isIn = info.IsIn && !ignoreByRefs; this.isOut = (info.IsOut && !this.isIn) && !ignoreByRefs; this.isOptional = info.IsOptional; }
private string GetAxTypeFromAssembly(string fileName, Guid clsid) { foreach (System.Type type in this.GetCopiedAssembly(fileName, true, false).GetTypes()) { if (typeof(AxHost).IsAssignableFrom(type)) { CustomAttributeTypedArgument argument = AxWrapperGen.GetAttributeData(type, typeof(AxHost.ClsidAttribute))[0].ConstructorArguments[0]; if (argument.Value.ToString() == ("{" + clsid.ToString() + "}")) { return(type.FullName); } } } return(null); }
/// <include file='doc\AxParameterData.uex' path='docs/doc[@for="AxParameterData.AxParameterData1"]/*' /> /// <devdoc> /// <para>[To be supplied.]</para> /// </devdoc> public AxParameterData(string inname, Type type) { Name = inname; this.type = type; this.typeName = AxWrapperGen.MapTypeName(type); }
internal static string GenerateWrappers(AxImporter importer, Guid axClsid, Assembly rcwAssem, string[] refAssemblies, DateTime tlbTimeStamp, out string assem) { assem = null; bool flag = false; CodeNamespace ns = null; string axctl = null; try { System.Type[] types = rcwAssem.GetTypes(); for (int i = 0; i < types.Length; i++) { if (IsTypeActiveXControl(types[i])) { flag = true; if (ns == null) { axctlNS = "Ax" + types[i].Namespace; ns = new CodeNamespace(axctlNS); } AxWrapperGen gen = new AxWrapperGen(types[i]); gen.GenerateAxHost(ns, refAssemblies); if (!axClsid.Equals(Guid.Empty) && axClsid.Equals(types[i].GUID)) { axctl = gen.axctl; } else if (axClsid.Equals(Guid.Empty) && (axctl == null)) { axctl = gen.axctl; } } } } finally { if (classesInNamespace != null) { classesInNamespace.Clear(); classesInNamespace = null; } } AssemblyName name = rcwAssem.GetName(); if (flag) { Version version = name.Version; assem = Compile(importer, ns, refAssemblies, tlbTimeStamp, version); if (assem != null) { if (axctl == null) { throw new Exception(System.Design.SR.GetString("AXNotValidControl", new object[] { "{" + axClsid + "}" })); } return (axctlNS + "." + axctl + "," + axctlNS); } } return null; }
private static bool IsValidType(AxWrapperGen.ComAliasEnum e, System.Type t) { switch (e) { case AxWrapperGen.ComAliasEnum.Color: return ((((t == typeof(ushort)) || (t == typeof(uint))) || (t == typeof(int))) || (t == typeof(short))); case AxWrapperGen.ComAliasEnum.Font: return GetGuid(t).Equals(Guid_IFont); case AxWrapperGen.ComAliasEnum.FontDisp: return GetGuid(t).Equals(Guid_IFontDisp); case AxWrapperGen.ComAliasEnum.Handle: return ((((t == typeof(uint)) || (t == typeof(int))) || (t == typeof(IntPtr))) || (t == typeof(UIntPtr))); case AxWrapperGen.ComAliasEnum.Picture: return GetGuid(t).Equals(Guid_IPicture); case AxWrapperGen.ComAliasEnum.PictureDisp: return GetGuid(t).Equals(Guid_IPictureDisp); } return false; }
public static bool IsPicture(AxWrapperGen.ComAliasEnum e) { if (e != AxWrapperGen.ComAliasEnum.Picture) { return (e == AxWrapperGen.ComAliasEnum.PictureDisp); } return true; }
public static bool IsFont(AxWrapperGen.ComAliasEnum e) { if (e != AxWrapperGen.ComAliasEnum.Font) { return (e == AxWrapperGen.ComAliasEnum.FontDisp); } return true; }
public static System.Type GetWFTypeFromComType(System.Type t, AxWrapperGen.ComAliasEnum alias) { if (IsValidType(alias, t)) { if (alias == AxWrapperGen.ComAliasEnum.Color) { return typeof(System.Drawing.Color); } if (IsFont(alias)) { return typeof(Font); } if (IsPicture(alias)) { return typeof(Image); } } return t; }
public static string GetWFToComParamConverter(AxWrapperGen.ComAliasEnum alias, System.Type t) { return t.FullName; }
public static string GetWFToComConverter(AxWrapperGen.ComAliasEnum alias) { if (alias == AxWrapperGen.ComAliasEnum.Color) { return "GetOleColorFromColor"; } if (IsFont(alias)) { return "GetIFontFromFont"; } if (IsPicture(alias)) { return "GetIPictureFromPicture"; } return ""; }
public static string GetComToWFParamConverter(AxWrapperGen.ComAliasEnum alias) { if (alias == AxWrapperGen.ComAliasEnum.Color) { return typeof(uint).FullName; } return ""; }
public static string GetComToManagedConverter(AxWrapperGen.ComAliasEnum alias) { if (alias == AxWrapperGen.ComAliasEnum.Color) { return "GetColorFromOleColor"; } if (IsFont(alias)) { return "GetFontFromIFont"; } if (IsPicture(alias)) { return "GetPictureFromIPicture"; } return ""; }
/// <include file='doc\AxImporter.uex' path='docs/doc[@for="AxImporter.GenerateFromTypeLibrary1"]/*' /> /// <devdoc> /// <para> /// Generates a wrapper for an ActiveX control for use in the design-time /// environment. /// </para> /// </devdoc> public string GenerateFromTypeLibrary(UCOMITypeLib typeLib, Guid clsid) { string axWFW = null; string axctlType = null; Assembly rcw = null; // Look to see if we can find the AxWrapper also for this typeLib. // axWFW = GetAxReference(typeLib); if (axWFW != null && clsid != Guid.Empty) { axctlType = GetAxTypeFromAssembly(axWFW, clsid); } if (axWFW == null) { string tlbName = Marshal.GetTypeLibName(typeLib); string rcwName = Path.Combine(options.outputDirectory, tlbName + ".dll"); Debug.WriteLineIf(AxWrapperGen.AxWrapper.Enabled, "Converting TypeLib Name: " + tlbName + " in " + rcwName); AddReferencedAssembly(GetManagedReference("System.Windows.Forms")); AddReferencedAssembly(GetManagedReference("System.Drawing")); AddReferencedAssembly(GetManagedReference("System")); string rcwAssem = GetComReference(typeLib); if (rcwAssem != null) { AddReferencedAssembly(rcwAssem); rcw = GetCopiedAssembly(rcwAssem, false, false); AddDependentAssemblies(rcw); } else { TypeLibConverter tlbConverter = new TypeLibConverter(); // Try to locate the primary interop assembly first. // rcw = GetPrimaryInteropAssembly(typeLib, tlbConverter); if (rcw != null) { rcwAssem = GetLocalPath(rcw.EscapedCodeBase); AddDependentAssemblies(rcw); } else { AssemblyBuilder asmBldr = tlbConverter.ConvertTypeLibToAssembly(typeLib, rcwName, (TypeLibImporterFlags)0, new ImporterCallback(this), options.publicKey, options.keyPair, null, null); if (rcwAssem == null) { // Save the assembly to the disk only if we did not find it already on the reference list. // rcwAssem = SaveAssemblyBuilder(typeLib, asmBldr, rcwName); rcw = GetCopiedAssembly(rcwAssem, false, false); } } } Debug.Assert(rcw != null, "No assembly obtained from: " + rcwAssem); // Create a list of the referenced assemblies and create the WFW Wrapper for the AxControl. // int i = 0; string[] refAssems = new string[this.refAssems.Count]; foreach (string assem in this.refAssems) { string name = assem; name = name.Replace("%20", " "); Debug.WriteLineIf(AxWrapperGen.AxWrapper.Enabled, "Adding " + name + " to the wrapper reference list..."); refAssems[i++] = name; } if (axctlType == null) { string file = GetFileOfTypeLib(typeLib); DateTime tlbTimeStamp = (file == null) ? DateTime.Now : File.GetLastWriteTime(file); // Hook up the type resolution events for the appdomain so we can delay load // any assemblies/types users gave us in the /i option. // ResolveEventHandler assemblyResolveEventHandler = new ResolveEventHandler(OnAssemblyResolve); AppDomain.CurrentDomain.AssemblyResolve += assemblyResolveEventHandler; try { if (options.genSources) { AxWrapperGen.GeneratedSources = new ArrayList(); } if (options.outputName == null) { options.outputName = "Ax" + tlbName + ".dll"; } axctlType = AxWrapperGen.GenerateWrappers(this, clsid, rcw, refAssems, tlbTimeStamp, out axWFW); if (options.genSources) { generatedSources = AxWrapperGen.GeneratedSources; } } finally { AppDomain.CurrentDomain.AssemblyResolve -= assemblyResolveEventHandler; } if (axctlType == null) { throw new Exception(SR.GetString(SR.AXNoActiveXControls, ((typeLibName != null) ? typeLibName : tlbName))); } } if (axctlType != null) { // Add the WFW assembly to the references list. // Debug.Assert(axWFW != null && axWFW.Length > 0, "Invalid output assembly name"); AddReferencedAssembly(axWFW); AddTypeLibAttr(typeLib); AddGeneratedAssembly(axWFW); } } return(axctlType); }
public string GenerateFromTypeLibrary(UCOMITypeLib typeLib, Guid clsid) { string fileName = null; string axTypeFromAssembly = null; Assembly assem = null; fileName = this.GetAxReference((System.Runtime.InteropServices.ComTypes.ITypeLib)typeLib); if ((fileName != null) && (clsid != Guid.Empty)) { axTypeFromAssembly = this.GetAxTypeFromAssembly(fileName, clsid); } if (fileName == null) { string typeLibName = Marshal.GetTypeLibName((System.Runtime.InteropServices.ComTypes.ITypeLib)typeLib); string asmFileName = Path.Combine(this.options.outputDirectory, typeLibName + ".dll"); this.AddReferencedAssembly(this.GetManagedReference("System.Windows.Forms")); this.AddReferencedAssembly(this.GetManagedReference("System.Drawing")); this.AddReferencedAssembly(this.GetManagedReference("System")); string comReference = this.GetComReference((System.Runtime.InteropServices.ComTypes.ITypeLib)typeLib); if (comReference != null) { this.AddReferencedAssembly(comReference); assem = this.GetCopiedAssembly(comReference, false, false); this.AddDependentAssemblies(assem, comReference); } else { TypeLibConverter tlbConverter = new TypeLibConverter(); assem = this.GetPrimaryInteropAssembly((System.Runtime.InteropServices.ComTypes.ITypeLib)typeLib, tlbConverter); if (assem != null) { comReference = this.GetLocalPath(assem.EscapedCodeBase); this.AddDependentAssemblies(assem, comReference); } else { AssemblyBuilder asmBldr = tlbConverter.ConvertTypeLibToAssembly((System.Runtime.InteropServices.ComTypes.ITypeLib)typeLib, asmFileName, TypeLibImporterFlags.None, new ImporterCallback(this), this.options.publicKey, this.options.keyPair, null, null); if (comReference == null) { comReference = this.SaveAssemblyBuilder((System.Runtime.InteropServices.ComTypes.ITypeLib)typeLib, asmBldr, asmFileName); assem = asmBldr; } } } int num = 0; string[] refAssemblies = new string[this.refAssems.Count]; foreach (string str6 in this.refAssems) { string str7 = str6; str7 = str7.Replace("%20", " "); refAssemblies[num++] = str7; } if (axTypeFromAssembly == null) { string fileOfTypeLib = GetFileOfTypeLib((System.Runtime.InteropServices.ComTypes.ITypeLib)typeLib); DateTime tlbTimeStamp = (fileOfTypeLib == null) ? DateTime.Now : File.GetLastWriteTime(fileOfTypeLib); ResolveEventHandler handler = new ResolveEventHandler(this.OnAssemblyResolve); AppDomain.CurrentDomain.AssemblyResolve += handler; AppDomain.CurrentDomain.TypeResolve += new ResolveEventHandler(this.OnTypeResolve); try { if (this.options.genSources) { AxWrapperGen.GeneratedSources = new ArrayList(); } if (this.options.outputName == null) { this.options.outputName = "Ax" + typeLibName + ".dll"; } axTypeFromAssembly = AxWrapperGen.GenerateWrappers(this, clsid, assem, refAssemblies, tlbTimeStamp, out fileName); if (this.options.genSources) { this.generatedSources = AxWrapperGen.GeneratedSources; } } finally { AppDomain.CurrentDomain.AssemblyResolve -= handler; AppDomain.CurrentDomain.TypeResolve -= new ResolveEventHandler(this.OnTypeResolve); } if (axTypeFromAssembly == null) { string message = System.Design.SR.GetString("AXNoActiveXControls", new object[] { (this.typeLibName != null) ? this.typeLibName : typeLibName }); if (this.options.msBuildErrors) { message = "AxImp: error aximp000: " + message; } throw new Exception(message); } } if (axTypeFromAssembly != null) { this.AddReferencedAssembly(fileName); this.AddTypeLibAttr((System.Runtime.InteropServices.ComTypes.ITypeLib)typeLib); this.AddGeneratedAssembly(fileName); } } return(axTypeFromAssembly); }