次の方法で共有


Type.GetTypeFromProgID メソッド (String, String)

指定したサーバーから、指定したプログラム ID (progID) に関連付けられている型を取得し、型の読み込み中にエラーが発生した場合は null を返します。

Overloads Public Shared Function GetTypeFromProgID( _
   ByVal progID As String, _   ByVal server As String _) As Type
[C#]
public static Type GetTypeFromProgID(stringprogID,stringserver);
[C++]
public: static Type* GetTypeFromProgID(String* progID,String* server);
[JScript]
public static function GetTypeFromProgID(
   progID : String,server : String) : Type;

パラメータ

  • progID
    取得する型の ProgID。
  • server
    型の読み込み元のサーバー。サーバー名が null 参照 (Visual Basic では Nothing) の場合、このメソッドは自動的にローカル マシンの名前を使用します。

戻り値

progID がレジストリの有効なエントリで、型がそれに関連付けられている場合は、指定したプログラム ID (ProgID) に関連付けられている型。それ以外の場合は null 参照 (Visual Basic では Nothing) 。

例外

例外の種類 条件
ArgumentException prodID が null 参照 (Visual Basic では Nothing) です。

解説

このメソッドは COM サポートに対して提供されます。プログラム ID の代わりに名前空間の概念が導入されたため、プログラム ID は Microsoft .NET Framework では使用されません。

使用例

[Visual Basic, C#, C++] ProgID とサーバー名を渡して型を取得する例を次に示します。この例では次に、ProgID に関連付けられている ClassID を表示するか、ProgID かサーバー名が無効な場合に例外をスローします。

 
Imports System
Class MainApp
    Public Shared Sub Main()
        Try
            ' Use ProgID localhost\HKEY_CLASSES_ROOT\DirControl.DirList.1.
            Dim theProgramID As String = "DirControl.DirList.1"
            ' Use Server name localhost.
            Dim theServer As String = "localhost"
            ' Make a call to the method to get the type information for the given ProgID.
            Dim myType As Type = Type.GetTypeFromProgID(theProgramID, theServer)
            If myType Is Nothing Then
                Throw New Exception("Invalid ProgID or server.")
            End If
            Console.WriteLine("GUID for ProgID DirControl.DirList.1 is {0}.", myType.GUID.ToString())
        Catch e As Exception
            Console.WriteLine("An exception occurred.")
            Console.WriteLine("Source: {0}.", e.Source.ToString())
            Console.WriteLine("Message: {0}.", e.Message.ToString())
        End Try
    End Sub 'Main
End Class 'MainApp

[C#] 
using System;
class MainApp 
{
    public static void Main()
    {
        try
        {
            // Use the ProgID localhost\HKEY_CLASSES_ROOT\DirControl.DirList.1.
            string theProgramID ="DirControl.DirList.1"; 
            // Use the server name localhost.
            string theServer="localhost";
            // Make a call to the method to get the type information for the given ProgID.
            Type myType =Type.GetTypeFromProgID(theProgramID,theServer);
            if(myType==null)
            {
                throw new Exception("Invalid ProgID or Server.");
            }
            Console.WriteLine("GUID for ProgID DirControl.DirList.1 is {0}.", myType.GUID);
        }
        catch(Exception e)
        {
            Console.WriteLine("An exception occurred.");
            Console.WriteLine("Source: {0}" , e.Source);
            Console.WriteLine("Message: {0}" , e.Message);
        }        
    }
}

[C++] 
#using <mscorlib.dll>

using namespace System;

int main() {
   try {
      // Use the ProgID localhost\HKEY_CLASSES_ROOT\DirControl::DirList.1.
      String* theProgramID =S"DirControl.DirList.1";
      // Use the server name localhost.
      String* theServer=S"localhost";
      // Make a call to the method to get the type information for the given ProgID.
      Type* myType =Type::GetTypeFromProgID(theProgramID, theServer);
      if (myType==0) {
         throw new Exception(S"Invalid ProgID or Server.");
      }
      Console::WriteLine(S"GUID for ProgID DirControl.DirList.1 is {0}.",__box( myType->GUID));
   } catch (Exception* e) {
      Console::WriteLine(S"An exception occurred.");
      Console::WriteLine(S"Source: {0}" , e->Source);
      Console::WriteLine(S"Message: {0}" , e->Message);
   }
}

[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 ファミリ

.NET Framework セキュリティ:

参照

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