TypeLibConverter.ConvertTypeLibToAssembly 方法
定義
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
將 COM 型別程式庫轉換為組件。
多載
ConvertTypeLibToAssembly(Object, String, Int32, ITypeLibImporterNotifySink, Byte[], StrongNameKeyPair, Boolean)
將 COM 型別程式庫轉換為組件。
public:
virtual System::Reflection::Emit::AssemblyBuilder ^ ConvertTypeLibToAssembly(System::Object ^ typeLib, System::String ^ asmFileName, int flags, System::Runtime::InteropServices::ITypeLibImporterNotifySink ^ notifySink, cli::array <System::Byte> ^ publicKey, System::Reflection::StrongNameKeyPair ^ keyPair, bool unsafeInterfaces);
public System.Reflection.Emit.AssemblyBuilder ConvertTypeLibToAssembly (object typeLib, string asmFileName, int flags, System.Runtime.InteropServices.ITypeLibImporterNotifySink notifySink, byte[] publicKey, System.Reflection.StrongNameKeyPair keyPair, bool unsafeInterfaces);
abstract member ConvertTypeLibToAssembly : obj * string * int * System.Runtime.InteropServices.ITypeLibImporterNotifySink * byte[] * System.Reflection.StrongNameKeyPair * bool -> System.Reflection.Emit.AssemblyBuilder
override this.ConvertTypeLibToAssembly : obj * string * int * System.Runtime.InteropServices.ITypeLibImporterNotifySink * byte[] * System.Reflection.StrongNameKeyPair * bool -> System.Reflection.Emit.AssemblyBuilder
Public Function ConvertTypeLibToAssembly (typeLib As Object, asmFileName As String, flags As Integer, notifySink As ITypeLibImporterNotifySink, publicKey As Byte(), keyPair As StrongNameKeyPair, unsafeInterfaces As Boolean) As AssemblyBuilder
參數
- typeLib
- Object
實作 ITypeLib
介面的物件。
- asmFileName
- String
產生的組件的檔案名稱。
- flags
- Int32
TypeLibImporterFlags 值,表示任何特別設定。
- notifySink
- ITypeLibImporterNotifySink
呼叫端所實作的.ITypeLibImporterNotifySink 介面。
- publicKey
- Byte[]
含有公開金鑰的 byte
陣列。
- keyPair
- StrongNameKeyPair
StrongNameKeyPair 物件,含有共用和私密的密碼編譯金鑰組。
- unsafeInterfaces
- Boolean
如果為 true
,則介面需要 UnmanagedCode 使用權限的連結時期檢查。 如果為 false
,則介面就必須進行需要堆疊查核行程 (Stack Walk) 以及較昂貴卻可以協助提供較多保護的執行階段檢查。
傳回
AssemblyBuilder 物件,包含已轉換的型別程式庫。
實作
例外狀況
所產生的中繼資料具有阻止任何型別載入的錯誤。
備註
如果您不想為元件產生強名稱,只要不等於 TypeLibImporterFlags.PrimaryInteropAssembly,flags
它就有效publicKey
且keyPair
為 null
。 否則,至少必須指定其中一個參數。 如果 publicKey
為 null
,中的 keyPair
公鑰將會設定在目標元件的指令清單元數據中,而且會根據元件的內容產生簽章。 如果 為 keyPair
null
, publicKey
則會在目標元件的指令清單元數據中設定,而且不會產生簽章。 同時指定這兩個參數並不實用,而且可能會導致簽章無效。
如需 的詳細資訊 ITypeLib
,請參閱 MSDN 文件庫中的現有檔。
適用於
ConvertTypeLibToAssembly(Object, String, TypeLibImporterFlags, ITypeLibImporterNotifySink, Byte[], StrongNameKeyPair, String, Version)
將 COM 型別程式庫轉換為組件。
public:
virtual System::Reflection::Emit::AssemblyBuilder ^ ConvertTypeLibToAssembly(System::Object ^ typeLib, System::String ^ asmFileName, System::Runtime::InteropServices::TypeLibImporterFlags flags, System::Runtime::InteropServices::ITypeLibImporterNotifySink ^ notifySink, cli::array <System::Byte> ^ publicKey, System::Reflection::StrongNameKeyPair ^ keyPair, System::String ^ asmNamespace, Version ^ asmVersion);
public System.Reflection.Emit.AssemblyBuilder ConvertTypeLibToAssembly (object typeLib, string asmFileName, System.Runtime.InteropServices.TypeLibImporterFlags flags, System.Runtime.InteropServices.ITypeLibImporterNotifySink notifySink, byte[] publicKey, System.Reflection.StrongNameKeyPair keyPair, string asmNamespace, Version asmVersion);
abstract member ConvertTypeLibToAssembly : obj * string * System.Runtime.InteropServices.TypeLibImporterFlags * System.Runtime.InteropServices.ITypeLibImporterNotifySink * byte[] * System.Reflection.StrongNameKeyPair * string * Version -> System.Reflection.Emit.AssemblyBuilder
override this.ConvertTypeLibToAssembly : obj * string * System.Runtime.InteropServices.TypeLibImporterFlags * System.Runtime.InteropServices.ITypeLibImporterNotifySink * byte[] * System.Reflection.StrongNameKeyPair * string * Version -> System.Reflection.Emit.AssemblyBuilder
Public Function ConvertTypeLibToAssembly (typeLib As Object, asmFileName As String, flags As TypeLibImporterFlags, notifySink As ITypeLibImporterNotifySink, publicKey As Byte(), keyPair As StrongNameKeyPair, asmNamespace As String, asmVersion As Version) As AssemblyBuilder
參數
- typeLib
- Object
實作 ITypeLib
介面的物件。
- asmFileName
- String
產生的組件的檔案名稱。
- flags
- TypeLibImporterFlags
TypeLibImporterFlags 值,表示任何特別設定。
- notifySink
- ITypeLibImporterNotifySink
呼叫端所實作的.ITypeLibImporterNotifySink 介面。
- publicKey
- Byte[]
含有公開金鑰的 byte
陣列。
- keyPair
- StrongNameKeyPair
StrongNameKeyPair 物件,含有共用和私密的密碼編譯金鑰組。
- asmNamespace
- String
產生組件的命名空間。
- asmVersion
- Version
產生組件的版本。 如果為 null
,則使用型別程式庫的版本。
傳回
AssemblyBuilder 物件,包含已轉換的型別程式庫。
實作
例外狀況
所產生的中繼資料具有阻止任何型別載入的錯誤。
範例
using namespace System;
using namespace System::Reflection;
using namespace System::Reflection::Emit;
using namespace System::Runtime::InteropServices;
enum class RegKind
{
RegKind_Default, RegKind_Register, RegKind_None
};
ref class ConversionEventHandler: public ITypeLibImporterNotifySink
{
public:
virtual void ReportEvent( ImporterEventKind eventKind, int eventCode, String^ eventMsg )
{
// handle warning event here...
}
virtual Assembly^ ResolveRef( Object^ typeLib )
{
// resolve reference here and return a correct assembly...
return nullptr;
}
};
[DllImport("oleaut32.dll",CharSet=CharSet::Unicode,PreserveSig=false)]
extern void LoadTypeLibEx( String^ strTypeLibName, RegKind regkind,
[MarshalAs(UnmanagedType::Interface)] interior_ptr<Object^> typeLib );
int main()
{
Object^ typeLib = gcnew Object;
LoadTypeLibEx( "SHDocVw.dll", RegKind::RegKind_None, &typeLib );
if ( typeLib == nullptr )
{
Console::WriteLine( "LoadTypeLibEx failed." );
return 0;
}
TypeLibConverter^ converter = gcnew TypeLibConverter;
ConversionEventHandler^ eventHandler = gcnew ConversionEventHandler;
AssemblyBuilder^ asmb = converter->ConvertTypeLibToAssembly( typeLib, "ExplorerLib.dll", (System::Runtime::InteropServices::TypeLibImporterFlags)0, eventHandler, nullptr, nullptr, nullptr, nullptr );
asmb->Save( "ExplorerLib.dll" );
}
using System;
using System.Reflection;
using System.Reflection.Emit;
using System.Runtime.InteropServices;
public class App
{
private enum RegKind
{
RegKind_Default = 0,
RegKind_Register = 1,
RegKind_None = 2
}
[ DllImport( "oleaut32.dll", CharSet = CharSet.Unicode, PreserveSig = false )]
private static extern void LoadTypeLibEx( String strTypeLibName, RegKind regKind,
[ MarshalAs( UnmanagedType.Interface )] out Object typeLib );
public static void Main()
{
Object typeLib;
LoadTypeLibEx( "SHDocVw.dll", RegKind.RegKind_None, out typeLib );
if( typeLib == null )
{
Console.WriteLine( "LoadTypeLibEx failed." );
return;
}
TypeLibConverter converter = new TypeLibConverter();
ConversionEventHandler eventHandler = new ConversionEventHandler();
AssemblyBuilder asm = converter.ConvertTypeLibToAssembly( typeLib, "ExplorerLib.dll", 0, eventHandler, null, null, null, null );
asm.Save( "ExplorerLib.dll" );
}
}
public class ConversionEventHandler : ITypeLibImporterNotifySink
{
public void ReportEvent( ImporterEventKind eventKind, int eventCode, string eventMsg )
{
// handle warning event here...
}
public Assembly ResolveRef( object typeLib )
{
// resolve reference here and return a correct assembly...
return null;
}
}
Imports System.Reflection
Imports System.Reflection.Emit
Imports System.Runtime.InteropServices
Public Class App
Private Enum RegKind
RegKind_Default = 0
RegKind_Register = 1
RegKind_None = 2
End Enum 'RegKind
<DllImport("oleaut32.dll", CharSet:=CharSet.Unicode, PreserveSig:=False)> _
Private Shared Sub LoadTypeLibEx(ByVal strTypeLibName As [String], ByVal regKind As RegKind, <MarshalAs(UnmanagedType.Interface)> ByRef typeLib As [Object])
End Sub
Public Shared Sub Main()
Dim typeLib As [Object]
LoadTypeLibEx("SHDocVw.dll", RegKind.RegKind_None, typeLib)
If typeLib Is Nothing Then
Console.WriteLine("LoadTypeLibEx failed.")
Return
End If
Dim converter As New TypeLibConverter()
Dim eventHandler As New ConversionEventHandler()
Dim asm As AssemblyBuilder = converter.ConvertTypeLibToAssembly(typeLib, "ExplorerLib.dll", 0, eventHandler, Nothing, Nothing, Nothing, Nothing)
asm.Save("ExplorerLib.dll")
End Sub
End Class
_
Public Class ConversionEventHandler
Implements ITypeLibImporterNotifySink
Public Sub ReportEvent(ByVal eventKind As ImporterEventKind, ByVal eventCode As Integer, ByVal eventMsg As String) Implements ITypeLibImporterNotifySink.ReportEvent
' handle warning event here...
End Sub
Public Function ResolveRef(ByVal typeLib As Object) As [Assembly] Implements ITypeLibImporterNotifySink.ResolveRef
' resolve reference here and return a correct assembly...
Return Nothing
End Function 'ResolveRef
End Class
備註
如果您不想為元件產生強名稱,只要不等於 TypeLibImporterFlags.PrimaryInteropAssembly,flags
它就有效publicKey
且keyPair
為 null
。 否則,至少必須指定其中一個參數。 如果 publicKey
為 null
,中的 keyPair
公鑰將會設定在目標元件的指令清單元數據中,而且會根據元件的內容產生簽章。 如果 為 keyPair
null
, publicKey
則會在目標元件的指令清單元數據中設定,而且不會產生簽章。 同時指定這兩個參數並不實用,而且可能會導致簽章無效。
如需 的詳細資訊 ITypeLib
,請參閱 MSDN 文件庫中的現有檔。