private void UpdateAssemblyLocation() { string fileName = null; NativeMethods.ITypeLib typeLib = null; try { NativeMethods.LoadTypeLibEx(this.typeLibraryLocation, NativeMethods.RegKind.RegKind_None, out typeLib); if (typeLib != null) { fileName = GetTypeLibName(typeLib); } } catch (COMException) { } finally { if (typeLib != null) { Marshal.ReleaseComObject(typeLib); } } if ((fileName == null) || (fileName.Length == 0)) { fileName = Path.GetFileNameWithoutExtension(this.typeLibraryLocation); fileName = fileName.Trim().Replace(" ", ""); } this.AssemblyLocation = fileName + ".dll"; }
private static string GetTypeLibName(NativeMethods.ITypeLib typeLib) { string strName = null; string strDocString = null; int dwHelpContext = 0; string strHelpFile = null; typeLib.GetDocumentation(-1, out strName, out strDocString, out dwHelpContext, out strHelpFile); return(strName); }
public void Convert(string typeLibraryLocation, string assemblyLocation, string assemblyNamespace, Version assemblyVersion, TypeLibImporterFlags flags, byte[] publicKey, StrongNameKeyPair keyPair) { string assemblyFile = Path.GetFileName(assemblyLocation); this.assemblyPath = Path.GetDirectoryName(assemblyLocation); NativeMethods.ITypeLib typeLib = null; try { if (!Directory.Exists(assemblyPath)) { Directory.CreateDirectory(assemblyPath); } this.RaiseMessage(string.Format("Loading '{0}'.", typeLibraryLocation)); NativeMethods.LoadTypeLibEx(typeLibraryLocation, NativeMethods.RegKind.RegKind_None, out typeLib); if (typeLib != null) { this.ConvertTypeLib(typeLib, assemblyPath, assemblyFile, assemblyNamespace, assemblyVersion, flags, publicKey, keyPair); } } catch (Exception exception) { this.RaiseError(exception.Message); } finally { if (typeLib != null) { Marshal.ReleaseComObject(typeLib); } } this.RaiseMessage("Done."); }