次の方法で共有


Type.GetTypeFromCLSID メソッド (Guid, Boolean)

型の読み込み中にエラーが発生した場合に例外をスローするかどうかを指定して、指定したクラス ID (CLSID) に関連付けられた型を取得します。

Overloads Public Shared Function GetTypeFromCLSID( _
   ByVal clsid As Guid, _   ByVal throwOnError As Boolean _) As Type
[C#]
public static Type GetTypeFromCLSID(Guidclsid,boolthrowOnError);
[C++]
public: static Type* GetTypeFromCLSID(Guidclsid,boolthrowOnError);
[JScript]
public static function GetTypeFromCLSID(
   clsid : Guid,throwOnError : Boolean) : Type;

パラメータ

  • clsid
    取得する型の CLSID。

  • throwOnError
    発生した例外をすべてスローする場合は true

    または

    発生した例外をすべて無視する場合は false

戻り値

CLSID が有効かどうかに関係なく System.__ComObject

解説

throwOnErrortrue に指定すると OutOfMemoryException などの例外がスローされますが、CLSID が未登録でも失敗することはありません。

使用例

[Visual Basic, C#, C++] 型の読み込み中にエラーが発生した場合に例外をスローするかどうかを指定して、ローカル ホストの CLSID に対応する型を取得する例を次に示します。

 
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] JScript のサンプルはありません。Visual Basic、C#、および C++ のサンプルを表示するには、このページの左上隅にある言語のフィルタ ボタン 言語のフィルタ をクリックします。

必要条件

プラットフォーム: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 ファミリ

参照

Type クラス | Type メンバ | System 名前空間 | Type.GetTypeFromCLSID オーバーロードの一覧