Type.GetTypeFromProgID メソッド
指定したプログラム ID (ProgID) に関連付けられている型を取得します。
オーバーロードの一覧
指定したプログラム ID (ProgID) に関連付けられている型を取得し、 Type の読み込み中にエラーが発生した場合は null を返します。
[Visual Basic] Overloads Public Shared Function GetTypeFromProgID(String) As Type
[JScript] public static function GetTypeFromProgID(String) : Type;
型の読み込み中にエラーが発生した場合に例外をスローするかどうかを指定して、指定したプログラム ID (ProgID) に関連付けられた型を取得します。
[Visual Basic] Overloads Public Shared Function GetTypeFromProgID(String, Boolean) As Type
[C++] public: static Type* GetTypeFromProgID(String*, bool);
[JScript] public static function GetTypeFromProgID(String, Boolean) : Type;
指定したサーバーから、指定したプログラム ID (progID) に関連付けられている型を取得し、型の読み込み中にエラーが発生した場合は null を返します。
[Visual Basic] Overloads Public Shared Function GetTypeFromProgID(String, String) As Type
[C++] public: static Type* GetTypeFromProgID(String*, String*);
[JScript] public static function GetTypeFromProgID(String, String) : Type;
型の読み込み中にエラーが発生した場合に例外をスローするかどうかを指定して、指定したサーバーの指定したプログラム ID (ProgID) に関連付けられた型を取得します。
[Visual Basic] Overloads Public Shared Function GetTypeFromProgID(String, String, Boolean) As Type
[C#] public static Type GetTypeFromProgID(string, string, bool);
[C++] public: static Type* GetTypeFromProgID(String*, String*, bool);
[JScript] public static function GetTypeFromProgID(String, String, Boolean) : Type;
使用例
[Visual Basic, C#, C++] ProgID とサーバー名を渡して型を取得する例を次に示します。この例では次に、ProgID かサーバー名が無効な場合に例外をスローするかどうかを指定して、ProgID に関連付けられている ClassID を表示します。
[Visual Basic, C#, C++] メモ ここでは、GetTypeFromProgID のオーバーロード形式のうちの 1 つだけについて、使用例を示します。その他の例については、各オーバーロード形式のトピックを参照してください。
Imports System
Class MainApp
Public Shared Sub Main()
Try
' Use Server localhost.
Dim theServer As String = "localhost"
' Use ProgID HKEY_CLASSES_ROOT\DirControl.DirList.1.
Dim myString1 As String = "DirControl.DirList.1"
' Use a wrong ProgID WrongProgID.
Dim myString2 As String = "WrongProgID"
' Make a call to the method to get the type information for the given ProgID.
Dim myType1 As Type = Type.GetTypeFromProgID(myString1, theServer, True)
Console.WriteLine("GUID for ProgID DirControl.DirList.1 is {0}.", myType1.GUID.ToString())
' Throw an exception because the ProgID is invalid and the throwOnError
' parameter is set to True.
Dim myType2 As Type = Type.GetTypeFromProgID(myString2, theServer, True)
Catch e As Exception
Console.WriteLine("An exception occurred. The ProgID is wrong.")
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 server localhost.
string theServer="localhost";
// Use ProgID HKEY_CLASSES_ROOT\DirControl.DirList.1.
string myString1 ="DirControl.DirList.1";
// Use a wrong ProgID WrongProgID.
string myString2 ="WrongProgID";
// Make a call to the method to get the type information for the given ProgID.
Type myType1 =Type.GetTypeFromProgID(myString1,theServer,true);
Console.WriteLine("GUID for ProgID DirControl.DirList.1 is {0}.", myType1.GUID);
// Throw an exception because the ProgID is invalid and the throwOnError
// parameter is set to True.
Type myType2 =Type.GetTypeFromProgID(myString2, theServer, true);
}
catch(Exception e)
{
Console.WriteLine("An exception occurred. The ProgID is wrong.");
Console.WriteLine("Source: {0}" , e.Source);
Console.WriteLine("Message: {0}" , e.Message);
}
}
}
[C++]
#using <mscorlib.dll>
using namespace System;
int main() {
try {
// Use server localhost.
String* theServer=S"localhost";
// Use ProgID HKEY_CLASSES_ROOT\DirControl.DirList.1.
String* myString1 =S"DirControl.DirList.1";
// Use a wrong ProgID WrongProgID.
String* myString2 =S"WrongProgID";
// Make a call to the method to get the type information for the given ProgID.
Type* myType1 =Type::GetTypeFromProgID(myString1, theServer, true);
Console::WriteLine(S"GUID for ProgID DirControl.DirList.1 is {0}.",__box( myType1->GUID));
// Throw an exception because the ProgID is invalid and the throwOnError
// parameter is set to True.
Type* myType2 =Type::GetTypeFromProgID(myString2, theServer, true);
} catch (Exception* e) {
Console::WriteLine(S"An exception occurred. The ProgID is wrong.");
Console::WriteLine(S"Source: {0}" , e->Source);
Console::WriteLine(S"Message: {0}" , e->Message);
}
}
[JScript] JScript のサンプルはありません。Visual Basic、C#、および C++ のサンプルを表示するには、このページの左上隅にある言語のフィルタ ボタン をクリックします。