Beispiel #1
0
        // This is used for the case of a class outside of a type
        // libarary
        protected Type GetTypeForClass()
        {
            Type type = null;

            // See if we have type lib information from the registry
            if (_typeLibString != null)
            {
                return(GetTypeFromTypeLib
                           (TypeLibrary.GetTypeLib(new Guid(_typeLibString),
                                                   _typeLibVersion)));
            }


            // Have to try and create the object and get the type lib
            // information from the created object

            if (TraceUtil.If(this, TraceLevel.Info))
            {
                TraceUtil.WriteLineInfo(this,
                                        "Attempting to create obj for: "
                                        + this);
            }


            IntPtr comObj;
            int    result = ActiveX.CoCreateInstance(ref _guid,
                                                     (IntPtr)0,
                                                     ActiveX.CLSCTX_SERVER,
                                                     ref ActiveX.IUnknownIID,
                                                     out comObj);

            if (result == 0)
            {
                ComObjectInfo objInfo = null;
                try
                {
                    // Wrap our object info stuff and get the type
                    objInfo = new ComObjectInfo(comObj);
                    type    = GetTypeFromTypeLib(objInfo.TypeLib);
                }
                catch (Exception ex)
                {
                    _typeFailedException =
                        new Exception("Unable to determine CLR type for "
                                      + GetName(), ex);
                    throw _typeFailedException;
                }
                finally
                {
                    try
                    {
                        // Clean up the object info, if we made it that
                        // far
                        if (objInfo != null)
                        {
                            Object o = objInfo.Obj;
                            ObjectInfo.RemoveObjectInfo(o);
                            while (true)
                            {
                                int count = Marshal.ReleaseComObject(o);
                                TraceUtil.WriteLineInfo
                                    (this,
                                    "final Marshal.ReleaseComObject count: "
                                    + count);
                                if (count <= 0)
                                {
                                    break;
                                }
                            }
                        }
                        while (true)
                        {
                            int count = Marshal.Release(comObj);
                            TraceUtil.WriteLineInfo
                                (this, "final Marshal.Release count: "
                                + count);

                            if (count <= 0)
                            {
                                break;
                            }
                        }
                    }
                    catch (Exception ex)
                    {
                        TraceUtil.WriteLineWarning
                            (this, "error on cleanup: " + ex);
                        // We tried...
                    }
                    ActiveX.CoFreeUnusedLibraries();
                }


                return(type);
            }

            _typeFailedException =
                new Exception("Unable to determine CLR type because "
                              + "I can't create a COM object (0x"
                              + result.ToString("X")
                              + ") from CLSID: " + _guidStr);
            throw _typeFailedException;
        }
Beispiel #2
0
        internal void GetBasicDetailText()
        {
            // The type library Guid comes from its key
            if (!(this is TypeLibrary) && _guidStr != null)
            {
                DetailPanel.Add(_infoType + " Guid",
                                !ObjectBrowser.INTERNAL,
                                21,
                                _guidStr);
            }

            // Get the CLR type if its available
            _displayedIdentifier = false;
            if (_container is TypeLibrary)
            {
                TypeLibrary typeLib = (TypeLibrary)_container;
                bool        findClass;
                if (this is ComClassInfo)
                {
                    findClass = TypeLibrary.FIND_CLASS;
                }
                else
                {
                    findClass = !TypeLibrary.FIND_CLASS;
                }
                Type type = typeLib.FindTypeByName(_name,
                                                   findClass);
                if (type != null)
                {
                    DetailPanel.AddLink("CLR Type",
                                        !ObjectBrowser.INTERNAL,
                                        15,
                                        TypeLinkHelper.TLHelper,
                                        type,
                                        HelpLinkHelper.
                                        MakeLinkModifier(type));
                    ComObjectInfo.GetDetailAxType(type, null, _infoType, 10);
                    _displayedIdentifier = true;
                }
                else
                {
                    DetailPanel.AddLink("Type Library",
                                        !ObjectBrowser.INTERNAL,
                                        25,
                                        ComLinkHelper.CLHelper,
                                        _container,
                                        HelpLinkHelper.MakeLinkModifier
                                            (_container._helpFile, 0));
                }
            }

            if (_helpFile != null)
            {
                DetailPanel.AddLink("Help File",
                                    !ObjectBrowser.INTERNAL,
                                    225,
                                    HelpLinkHelper.HLHelper,
                                    HelpLinkHelper.MakeLinkModifier
                                        (_helpFile, 0));
                if (_helpContext != 0)
                {
                    DetailPanel.AddLink("Help Context",
                                        !ObjectBrowser.INTERNAL,
                                        227,
                                        HelpLinkHelper.HLHelper,
                                        HelpLinkHelper.MakeLinkModifier
                                            (_helpFile, _helpContext));
                }
            }

            // Type library description is displayed in the type library stuff
            if (DocString != null && !(this is TypeLibrary))
            {
                DetailPanel.Add("Description",
                                !ObjectBrowser.INTERNAL,
                                23,
                                DocString);
            }

            // Show everything in the registry
            if (!(this is TypeLibrary) && _regKey != null)
            {
                try {
                    string[] keys = _regKey.GetSubKeyNames();
                    foreach (String str in keys)
                    {
                        RegistryKey key   = _regKey.OpenSubKey(str);
                        string      value = (string)key.GetValue(null);
                        // If there is no value, see if there are any subkeys
                        if (value == null || value.Equals(""))
                        {
                            String[] subKeys = key.GetSubKeyNames();
                            if (subKeys.Length > 0)
                            {
                                foreach (string subStr in subKeys)
                                {
                                    AddRegistryValue(str, subStr);
                                }
                            }
                            else
                            {
                                AddRegistryValue(str, null);
                            }
                        }
                        else
                        {
                            AddRegistryValue(str, (string)key.GetValue(null));
                        }
                    }
                } catch {
                    // ignore errors
                }
            }
        }
		// This is used for the case of a class outside of a type
		// libarary
		protected Type GetTypeForClass()
		{
			Type type = null;

			// See if we have type lib information from the registry
			if (_typeLibString != null)
			{
				return GetTypeFromTypeLib
					(TypeLibrary.GetTypeLib(new Guid(_typeLibString),
											_typeLibVersion));
			}


			// Have to try and create the object and get the type lib
			// information from the created object

			if (TraceUtil.If(this, TraceLevel.Info))
			{
				TraceUtil.WriteLineInfo(this,
										"Attempting to create obj for: "
										+ this);
			}


			IntPtr comObj;
			int result = ActiveX.CoCreateInstance(ref _guid,
												  (IntPtr)0,
												  ActiveX.CLSCTX_SERVER,
												  ref ActiveX.IUnknownIID,
												  out comObj);
			if (result == 0)
			{
				ComObjectInfo objInfo = null;
				try
				{
					// Wrap our object info stuff and get the type
					objInfo = new ComObjectInfo(comObj);
					type = GetTypeFromTypeLib(objInfo.TypeLib);
				}
				catch (Exception ex)
				{
					_typeFailedException = 
						new Exception("Unable to determine CLR type for "
									  + GetName(), ex);
					throw _typeFailedException;
				}
				finally
				{
					try
					{
						// Clean up the object info, if we made it that
						// far
						if (objInfo != null)
						{
							Object o = objInfo.Obj;
							ObjectInfo.RemoveObjectInfo(o);
							while (true)
							{
								int count = Marshal.ReleaseComObject(o);
								TraceUtil.WriteLineInfo
									(this,
									 "final Marshal.ReleaseComObject count: " 
									 + count);
								if (count <= 0)
									break;
							}
						}
						while (true)
						{
							int count = Marshal.Release(comObj);
							TraceUtil.WriteLineInfo
								(this, "final Marshal.Release count: " 
								 + count);

							if (count <= 0)
								break;
						}
					}
					catch (Exception ex)
					{
						TraceUtil.WriteLineWarning
							(this, "error on cleanup: " + ex);
						// We tried...
					}
					ActiveX.CoFreeUnusedLibraries();
				}

				
				return type;
			}

			_typeFailedException = 
				new Exception("Unable to determine CLR type because "
								+ "I can't create a COM object (0x"
								+ result.ToString("X")
								+ ") from CLSID: " + _guidStr);
			throw _typeFailedException;

		}