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.
[Visual Basic] Overloads Public Shared Function GetTypeFromCLSID( _ ByVal clsid As Guid, _ ByVal throwOnError As Boolean _ ) As Type [C#] public static Type GetTypeFromCLSID( Guid clsid, bool throwOnError ); [C++] public: static Type* GetTypeFromCLSID( Guid clsid, bool throwOnError ); [JScript] public static function GetTypeFromCLSID( clsid : Guid, throwOnError : Boolean ) : Type;
Parameters
- clsid
- The CLSID of the type to get.
- throwOnError
- true to throw any exception that occurs.
-or-
false to ignore any exception that occurs.
Return Value
System.__ComObject regardless of whether the CLSID is valid.
Remarks
Exceptions such as OutOfMemoryException will be thrown when specifying true for throwOnError, but it will not fail for unregistered CLSIDs.
Example
[Visual Basic, C#, C++] The following example retrieves the type associated with the CLSID from the local host, specifying whether to throw an exception if an error occurs while loading the type.
[Visual Basic] Imports System Class MyGetTypeFromCLSIDSample Public Shared Sub Main() Try ' Create a GUID. Dim myGuid1 As New Guid("1DCD0710-0B41-11D3-A565-00C04F8EF6E3") ' Get the type associated with the CLSID ' and specify whether to throw an exception if an error occurs ' while loading the type. Dim myType1 As Type = Type.GetTypeFromCLSID(myGuid1, True) Console.WriteLine("The GUID associated with myType1 is {0}.", myType1.GUID.ToString()) Console.WriteLine("The type of the GUID is {0}.", myType1.ToString()) [C#] using System; class MyGetTypeFromCLSIDSample { public static void Main() { try { // Create a GUID. Guid myGuid1 = new Guid("1DCD0710-0B41-11D3-A565-00C04F8EF6E3"); // Get the type associated with the CLSID // and specify whether to throw an exception if an error occurs // while loading the type. Type myType1 =Type.GetTypeFromCLSID(myGuid1, true); Console.WriteLine("The GUID associated with myType1 is {0}.", myType1.GUID); Console.WriteLine("The type of the GUID is {0}.", myType1.ToString()); [C++] #using <mscorlib.dll> using namespace System; int main() { try { // Create a GUID. Guid myGuid1 = Guid(S"1DCD0710-0B41-11D3-A565-00C04F8EF6E3"); // Get the type associated with the CLSID // and specify whether to throw an exception if an error occurs // while loading the type. Type* myType1 =Type::GetTypeFromCLSID(myGuid1, true); Console::WriteLine(S"The GUID associated with myType1 is {0}.",__box( myType1->GUID)); Console::WriteLine(S"The type of the GUID is {0}.", myType1);
[JScript] No example is available for JScript. To view a Visual Basic, C#, or C++ example, click the Language Filter button
in the upper-left corner of the page.
Requirements
Platforms: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 family
See Also
Type Class | Type Members | System Namespace | Type.GetTypeFromCLSID Overload List