當前位置: 首頁>>代碼示例>>VB.NET>>正文


VB.NET Type.GetTypeFromCLSID方法代碼示例

本文整理匯總了VB.NET中System.Type.GetTypeFromCLSID方法的典型用法代碼示例。如果您正苦於以下問題:VB.NET Type.GetTypeFromCLSID方法的具體用法?VB.NET Type.GetTypeFromCLSID怎麽用?VB.NET Type.GetTypeFromCLSID使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在System.Type的用法示例。


在下文中一共展示了Type.GetTypeFromCLSID方法的5個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的VB.NET代碼示例。

示例1: Example

' 導入命名空間
Imports System.Reflection
Imports System.Runtime.InteropServices

Module Example
   Private Const WORD_CLSID As String = "{000209FF-0000-0000-C000-000000000046}"
   
   Public Sub Main()
      Try
         ' Start an instance of the Word application.
         Dim word As Type = Type.GetTypeFromCLSID(Guid.Parse(WORD_CLSID), 
                                                  "computer17.central.contoso.com",
                                                  True)
         Console.WriteLine("Instantiated Type object from CLSID {0}",
                           WORD_CLSID)

         Dim wordObj As Object = Activator.CreateInstance(word)
         Console.WriteLine("Instantiated {0}", 
                           wordObj.GetType().FullName)
         
         ' Close Word.
         word.InvokeMember("Quit", BindingFlags.InvokeMethod, Nothing, 
                           wordObj, New Object() { 0, 0, False } )
      ' The method can throw any of a variety of exceptions.
      Catch e As Exception
         Console.WriteLine("{0}: Unable to instantiate an object for {1}", 
                           e.GetType().Name, WORD_CLSID)
      End Try
   End Sub
End Module
開發者ID:VB.NET開發者,項目名稱:System,代碼行數:30,代碼來源:Type.GetTypeFromCLSID

輸出:

Instantiated Type object from CLSID {000209FF-0000-0000-C000-000000000046}
Instantiated Microsoft.Office.Interop.Word.ApplicationClass

示例2: ExplicitGuid

' 導入命名空間
Imports System.Runtime.InteropServices

<Assembly:ComVisible(True)>

' Define two classes, and assign one an explicit GUID.
<GuidAttribute("d055cba3-1f83-4bd7-ba19-e22b1b8ec3c4")>
Public Class ExplicitGuid
End Class

Public Class NoExplicitGuid
End Class

Module Example
   Public Sub Main()
      Dim explicitType As Type = GetType(ExplicitGuid)
      Dim explicitGuid As Guid = explicitType.GUID
      
      ' Get type of ExplicitGuid from its GUID.
      Dim explicitCOM As Type = Type.GetTypeFromCLSID(explicitGuid)
      Console.WriteLine("Created {0} type from CLSID {1}",
                        explicitCOM.Name, explicitGuid)
                        
      ' Compare the two type objects.
      Console.WriteLine("{0} and {1} equal: {2}",
                        explicitType.Name, explicitCOM.Name,
                        explicitType.Equals(explicitCOM))                  
      
      ' Instantiate an ExplicitGuid object.
      Try 
         Dim obj As Object = Activator.CreateInstance(explicitCOM)
         Console.WriteLine("Instantiated a {0} object", obj.GetType().Name)
      Catch e As COMException
         Console.WriteLine("COM Exception:{1}{0}{1}", e.Message, vbCrLf)   
      End Try 
        
      Dim notExplicit As Type = GetType(NoExplicitGuid)
      Dim notExplicitGuid As Guid = notExplicit.GUID
      
      ' Get type of ExplicitGuid from its GUID.
      Dim notExplicitCOM As Type = Type.GetTypeFromCLSID(notExplicitGuid)
      Console.WriteLine("Created {0} type from CLSID {1}",
                        notExplicitCOM.Name, notExplicitGuid)
                        
      ' Compare the two type objects.
      Console.WriteLine("{0} and {1} equal: {2}",
                        notExplicit.Name, notExplicitCOM.Name,
                        notExplicit.Equals(notExplicitCOM))                  
      
      ' Instantiate an ExplicitGuid object.
      Try 
         Dim obj As Object = Activator.CreateInstance(notExplicitCOM)
         Console.WriteLine("Instantiated a {0} object", obj.GetType().Name)
      Catch e As COMException
         Console.WriteLine("COM Exception:{1}{0}{1}", e.Message, vbCrLf)   
      End Try 
   End Sub
End Module
開發者ID:VB.NET開發者,項目名稱:System,代碼行數:58,代碼來源:Type.GetTypeFromCLSID

輸出:

Created __ComObject type from CLSID d055cba3-1f83-4bd7-ba19-e22b1b8ec3c4
ExplicitGuid and __ComObject equal: False
COM Exception:
Retrieving the COM class factory for component with CLSID 
{D055CBA3-1F83-4BD7-BA19-E22B1B8EC3C4} failed due to the following error: 
80040154 Class not registered 
(Exception from HRESULT: 0x80040154 (REGDB_E_CLASSNOTREG)).

Created __ComObject type from CLSID 74f03346-a718-3516-ac78-f351c7459ffb
NoExplicitGuid and __ComObject equal: False
COM Exception:
Retrieving the COM class factory for component with CLSID 
{74F03346-A718-3516-AC78-F351C7459FFB} failed due to the following error: 
80040154 Class not registered 
(Exception from HRESULT: 0x80040154 (REGDB_E_CLASSNOTREG)).

示例3: Example

' 導入命名空間
Imports System.Reflection
Imports System.Runtime.InteropServices

Module Example
   Private Const WORD_CLSID As String = "{000209FF-0000-0000-C000-000000000046}"
   
   Public Sub Main()
      ' Start an instance of the Word application.
      Dim word As Type = Type.GetTypeFromCLSID(Guid.Parse(WORD_CLSID), "computer17.central.contoso.com")
      Console.WriteLine("Instantiated Type object from CLSID {0}",
                        WORD_CLSID)
      Try
         Dim wordObj As Object = Activator.CreateInstance(word)
         Console.WriteLine("Instantiated {0}", 
                           wordObj.GetType().FullName)
         
         ' Close Word.
         word.InvokeMember("Quit", BindingFlags.InvokeMethod, Nothing, 
                           wordObj, New Object() { 0, 0, False } )
      Catch e As COMException
         Console.WriteLine("Unable to instantiate object.")
      End Try
   End Sub
End Module
開發者ID:VB.NET開發者,項目名稱:System,代碼行數:25,代碼來源:Type.GetTypeFromCLSID

輸出:

Instantiated Type object from CLSID {000209FF-0000-0000-C000-000000000046}
Instantiated Microsoft.Office.Interop.Word.ApplicationClass

示例4: Example

' 導入命名空間
Imports System.Reflection
Imports System.Runtime.InteropServices

Module Example
   Private Const WORD_CLSID As String = "{000209FF-0000-0000-C000-000000000046}"
   
   Public Sub Main()
      ' Start an instance of the Word application.
      Try
         Dim word As Type = Type.GetTypeFromCLSID(Guid.Parse(WORD_CLSID), True)
         Console.WriteLine("Instantiated Type object from CLSID {0}",
                           WORD_CLSID)
         Dim wordObj As Object = Activator.CreateInstance(word)
         Console.WriteLine("Instantiated {0}", 
                           wordObj.GetType().FullName)
         
         ' Close Word.
         word.InvokeMember("Quit", BindingFlags.InvokeMethod, Nothing, 
                           wordObj, New Object() { 0, 0, False } )
      ' The method can throw any of a number of unexpected exceptions.
      Catch e As Exception
         Console.WriteLine("Unable to instantiate an object for {0}", WORD_CLSID)
      End Try
   End Sub
End Module
開發者ID:VB.NET開發者,項目名稱:System,代碼行數:26,代碼來源:Type.GetTypeFromCLSID

輸出:

Instantiated Type object from CLSID {000209FF-0000-0000-C000-000000000046}
Instantiated Microsoft.Office.Interop.Word.ApplicationClass

示例5: Example

' 導入命名空間
Imports System.Reflection
Imports System.Runtime.InteropServices

Module Example
   Private Const WORD_CLSID As String = "{000209FF-0000-0000-C000-000000000046}"
   
   Public Sub Main()
      ' Start an instance of the Word application.
      Dim word As Type = Type.GetTypeFromCLSID(Guid.Parse(WORD_CLSID))
      Console.WriteLine("Instantiated Type object from CLSID {0}",
                        WORD_CLSID)
      Dim wordObj As Object = Activator.CreateInstance(word)
      Console.WriteLine("Instantiated {0}", 
                        wordObj.GetType().FullName)
      
      ' Close Word.
      word.InvokeMember("Quit", BindingFlags.InvokeMethod, Nothing, 
                        wordObj, New Object() { 0, 0, False } )
   End Sub
End Module
開發者ID:VB.NET開發者,項目名稱:System,代碼行數:21,代碼來源:Type.GetTypeFromCLSID

輸出:

Instantiated Type object from CLSID {000209FF-0000-0000-C000-000000000046}
Instantiated Microsoft.Office.Interop.Word.ApplicationClass


注:本文中的System.Type.GetTypeFromCLSID方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。