Type::GetTypeFromCLSID Method (Guid, Boolean)

Gets the type associated with the specified class identifier (CLSID), specifying whether to throw an exception if an error occurs while loading the type.

Namespace:  System
Assembly:  mscorlib (in mscorlib.dll)

public:
static Type^ GetTypeFromCLSID(
	Guid clsid, 
	bool throwOnError
)

Parameters

clsid
Type: System::Guid

The CLSID of the type to get.

throwOnError
Type: System::Boolean

true to throw any exception that occurs.

-or-

false to ignore any exception that occurs.

Return Value

Type: System::Type
System.__ComObject regardless of whether the CLSID is valid.

The GetTypeFromCLSID method supports late-bound access to COM objects from .NET Framework apps when you know the object's class identifier (CLSID). The class identifier for COM classes is defined in the HKEY_CLASSES_ROOT\CLSID key of the registry. You can retrieve the value of the IsCOMObject property to determine whether the type returned by this method is a COM object.

TipTip

You can call the GetTypeFromProgID method for late-bound access to COM objects whose programmatic identifier (ProgID) you know.

Instantiating a COM object from its CLSID is a two-step process:

  1. Get a Type object that represents the __ComObject that corresponds to the CLSID by calling the GetTypeFromCLSID method.

  2. Call the Activator::CreateInstance(Type) method to instantiate the COM object.

See the example for an illustration.

Exceptions such as OutOfMemoryException will be thrown when specifying true for throwOnError, but it will not fail for unregistered CLSIDs.

Notes to Callers

This method is intended for use when working with COM objects, not with .NET Framework objects. Although the method returns a Type object that corresponds to the GUID for .NET Framework objects, you can't use that Type object to create a type instance by calling the Activator::CreateInstance method, as the following example shows.

No code example is currently available or this language may not be supported.

The following example uses the CLSID of the Microsoft Word Application object to retrieve a COM type that represents the Microsoft Word application. It then instantiates the type by calling the Activator::CreateInstance method, and closes it by calling the Application.Quit method. An exception is thrown if an error occurs while loading the type.

No code example is currently available or this language may not be supported.

.NET Framework

Supported in: 4.5, 4, 3.5, 3.0, 2.0, 1.1, 1.0

.NET Framework Client Profile

Supported in: 4, 3.5 SP1

Windows 8.1, Windows Server 2012 R2, Windows 8, Windows Server 2012, Windows 7, Windows Vista SP2, Windows Server 2008 (Server Core Role not supported), Windows Server 2008 R2 (Server Core Role supported with SP1 or later; Itanium not supported)

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

Was this page helpful?
(1500 characters remaining)
Thank you for your feedback
Show:
© 2014 Microsoft