// Called when a type library is loaded from the remembered
		// type libraries upon start up
		internal static void RestoreTypeLib(String fileName,
											Guid guid,
											string version)
		{
			TypeLibrary lib = null;
			try {
				lock (typeof(TypeLibrary)) {
					TraceUtil.WriteLineInfo(null, 
											"RestoreTypeLib - guid/version: " 
											+ guid + " " + version);
						
					TypeLibKey typeLibKey = new TypeLibKey(guid, version);
					// We should not have already seen this one, but
					// if we have, we will be decent about it
					lib = (TypeLibrary)_openedTypeLibs[typeLibKey];
					if (lib == null) {
						lib = new TypeLibrary(typeLibKey);
						try {
							lib.PopulateFromRegistry(typeLibKey);
						}
						catch (Exception ex) {
							// Get the file name we recorded since its not
							// registered
							lib._fileName = fileName;
							// Might not be registered, ignore error
							TraceUtil.WriteLineInfo
								(typeof(TypeLibrary),
								"Unregistered typelib restore: " 
								+ fileName 
								+ " exception: " + ex);
						}
					}
					lib.ReadTypeLibFile();
					if (lib._openedFile) {
						if (!_searchMode) {
							ComSupport.AddTypeLib(lib);
						}
						TraceUtil.WriteLineInfo(null, 
												"TypeLib - loaded/restored: " 
												+ lib);
					} else {
						// Something's wrong, don't try and open again
						lib.ForgetMe();
						TraceUtil.WriteLineInfo(null, 
												"TypeLib - failed to open "
												+ "- forgotten: " 
												+ lib);
					}
				}
			} catch (Exception ex) {
				TraceUtil.WriteLineWarning
					(null, "TypeLib - deleting bad typelib entry: " 
					+ lib + " " + ex);
				// Something's wrong, don't try and open again
				lib.ForgetMe();
			}
		}
		// If the UCOMITypeLib pointer is good, then remember
		// that, because the type library may not be in the registry
		// or a file we can open.  But we can still convert it and
		// read its information
		internal static TypeLibrary GetTypeLib(TypeLibKey key, UCOMITypeLib iTypeLib)
		{
			TraceUtil.WriteLineInfo(null, "TypeLib - GetTypeLib: " + key);
			lock (typeof(TypeLibrary)) {
				TypeLibrary lib = (TypeLibrary)_openedTypeLibs[key];
				if (lib != null && lib._converted)
					return lib;
				try {
					if (lib == null) {
						// Have to create one
						lib = new TypeLibrary(key);
						lib._iTypeLib = iTypeLib;
						try {
							lib.PopulateFromRegistry(key);
						} catch (Exception ex) {
							// This could be ok, sometimes a typelib is not
							// in the registry
							TraceUtil.WriteLineWarning
								(typeof(TypeLibrary),
								"GetTypeLib exception (not in registry)  "
								+ ex);
							if (lib._iTypeLib == null) {
								throw new Exception("Failed to find type library information in registry", ex);
							}
						}
					}
					lib.TranslateTypeLib();
					// Generate the C# source after the translation for
					// now because the source generation requires the 
					// definitions to be read which can cause a call
					// to GetTypeLib(), don't want to be re-entered
					// FIXME
					//lib.GenerateSource();
					return lib;
				} catch (Exception ex) {
					TraceUtil.WriteLineWarning(typeof(TypeLibrary), "GetTypeLib exception " + ex);
					throw new Exception("Error getting type library: ", ex);
				}
			}
		}
		protected static void GetTypeLibsFromRegistry(String guidStr)
		{
			TypeLibrary lib = null;
			RegistryKey regKey = Windows.KeyTypeLib.OpenSubKey(guidStr);
			String[] subKeyNames = regKey.GetSubKeyNames();
			foreach (String versionStr in subKeyNames) {
				RegistryKey versionKey = regKey.OpenSubKey(versionStr);
				try {
					if (versionKey == null) {
						throw new Exception("Version entry not "
											+ "found for typelib: " 
											+ guidStr);
					}
					TypeLibKey key = new TypeLibKey(new Guid(guidStr), versionStr);
					// See if we already know about it
					TypeLibrary convLib = (TypeLibrary)_openedTypeLibs[key];
					if (convLib == null) {
						lib = new TypeLibrary();
						lib.Key = key;
						lib.PopulateFromRegistry(versionKey);
						// We don't read the type lib info until the user
						// wants the detail text or something else 
						// that requires it
					} else {
						lib = convLib;
					}
					_registeredTypeLibs.Add(lib, lib);
				} catch (Exception ex) {
					TraceUtil.WriteLineInfo(null,
											"TypeLib - failure to read: "
											+ versionKey + " " + ex);
				}
			}
		}