Tlbexp.exe (類型程式庫匯出工具)Tlbexp.exe (Type Library Exporter)

類型程式庫匯出工具可以產生類型程式庫,這個類型程式庫描述定義在通用語言執行平台組件中的類型。The Type Library Exporter generates a type library that describes the types defined in a common language runtime assembly.

此工具會自動與 Visual Studio 一起安裝。This tool is automatically installed with Visual Studio. 若要執行此工具,請使用 [Visual Studio 開發人員命令提示字元] (或 Windows 7 中的 [Visual Studio 命令提示字元])。To run the tool, use the Developer Command Prompt for Visual Studio (or the Visual Studio Command Prompt in Windows 7). 如需詳細資訊,請參閱命令提示字元For more information, see Command Prompts.

在命令提示字元下輸入下列命令:At the command prompt, type the following:

語法Syntax

tlbexp assemblyName [options]  

參數Parameters

引數Argument 描述Description
assemblyNameassemblyName 要匯出類型程式庫的組件。The assembly for which to export a type library.
選項Option 描述Description
/asmpath: 目錄/asmpath: directory 指定要搜尋組件的位置。Specifies the location to search for assemblies. 如果使用這個選項,則必須明確指定要搜尋參考組件的位置,包括目前的目錄在內。If you use this option, you must explicitly specify the locations to search for referenced assemblies, including the current directory.

當您使用 asmpath 選項時,型別程式庫匯出工具不會在全域組件快取 (GAC) 中尋找組件。When you use the asmpath option, the Type Library Exporter will not look for an assembly in the global assembly cache (GAC).
/help/help 顯示工具的命令語法和選項。Displays command syntax and options for the tool.
/names: filename/names: filename 指定類型程式庫中名稱的大小寫。Specifies the capitalization of names in a type library. filename 引數是一個文字檔。The filename argument is a text file. 檔案中的每一行指定了類型程式庫中一個名稱的大小寫。Each line in the file specifies the capitalization of one name in the type library.
/nologo/nologo 隱藏 Microsoft 程式啟始資訊顯示。Suppresses the Microsoft startup banner display.
/oldnames/oldnames 在發生類型名稱衝突時,強制 Tlbexp.exe 匯出裝飾類型名稱。Forces Tlbexp.exe to export decorated type names if there is a type name conflict. 請注意,此為 .NET Framework 2.0 版之前版本中的預設行為。Note that this was the default behavior in versions prior to the .NET Framework version 2.0.
/out: file/out: file 指定要產生的類型程式庫檔案的名稱。Specifies the name of the type library file to generate. 如果省略這個選項,Tlbexp.exe 會產生一個與組件名稱 (指實際組件名稱,不一定和包含組件的檔案同名) 相同的類型程式庫和 .tlb 副檔名。If you omit this option, Tlbexp.exe generates a type library with the same name as the assembly (the actual assembly name, which might not necessarily be the same as the file containing the assembly) and a .tlb extension.
/silence: warningnumber/silence: warningnumber 隱藏顯示指定的警告。Suppresses the display of the specified warning. 此選項無法搭配 /silent 使用。This option cannot be used with /silent.
/silent/silent 隱藏顯示成功訊息。Suppresses the display of success messages. 此選項無法搭配 /silence 使用。This option cannot be used with /silence.
/tlbreference: typelibraryname/tlbreference: typelibraryname 強制 Tlbexp.exe 明確解析類型程式庫參考,而不需查閱登錄。Forces Tlbexp.exe to explicitly resolve type library references without consulting the registry. 例如,如果組件 B 參考組件 A,您就可以使用這個選項提供明確的類型程式庫參考,而不需依賴登錄中所指定的類型程式庫。For example, if assembly B references assembly A, you can use this option to provide an explicit type library reference, rather than relying on the type library specified in the registry. Tlbexp.exe 會執行版本檢查,以確定類型程式庫版本是否與組件版本相符;如果不符,便會產生錯誤。Tlbexp.exe performs a version check to ensure that the type library version matches the assembly version; otherwise, it generates an error.

請注意,如果將 ComImportAttribute 屬性套用至介面,然後又由其他類型實作,則 tlbreference 選項仍然會查閱登錄。Note that the tlbreference option still consults the registry in cases where the ComImportAttribute attribute is applied to an interface that is then implemented by another type.
/tlbrefpath: path/tlbrefpath: path 參考類型程式庫的完整路徑。Fully qualified path to a referenced type library.
/win32/win32 在 64 位元電腦上編譯時,這個選項會指定 Tlbexp.exe 產生 32 位元的類型程式庫。When compiling on a 64-bit computer, this option specifies that Tlbexp.exe generates a 32-bit type library.
/win64/win64 在 32 位元電腦上編譯時,這個選項會指定 Tlbexp.exe 產生 64 位元的型別程式庫。When compiling on a 32-bit computer, this option specifies that Tlbexp.exe generates a 64-bit type library.
/verbose/verbose 指定詳細資訊模式,顯示需要產生類型程式庫的任何參考組件的清單。Specifies verbose mode; displays a list of any referenced assemblies for which a type library needs to be generated.
/?/? 顯示工具的命令語法和選項。Displays command syntax and options for the tool.

注意

Tlbexp.exe 的命令列選項不區分大小寫,而且可以依任何順序提供。The command-line options for Tlbexp.exe are case-insensitive and can be supplied in any order. 您只需要指定足夠的選項來唯一識別它。You only need to specify enough of the option to uniquely identify it. 例如, /n 相當於 /nologo,且 /o: outfile.tlb 相當於 /out: outfile.tlbFor example, /n is equivalent to /nologo, and /o: outfile.tlb is equivalent to /out: outfile.tlb.

備註Remarks

Tlbexp.exe 會產生一個類型程式庫,其含有組件中所定義的類型定義。Tlbexp.exe generates a type library that contains definitions of the types defined in the assembly. 應用程式 (例如 Visual Basic 6.0) 可以使用產生的類型程式庫來繫結至組件中所定義的 .NET 類型。Applications such as Visual Basic 6.0 can use the generated type library to bind to the .NET types defined in the assembly.

重要

您無法使用 Tlbexp.exe 匯出 Windows 中繼資料 (.winmd) 檔案。You cannot use Tlbexp.exe to export Windows metadata (.winmd) files. 不支援匯出 Windows 執行階段組件。Exporting Windows Runtime assemblies is not supported.

全部組件會一次同時轉換。The entire assembly is converted at once. 您無法使用 Tlbexp.exe 來為組件中所定義的類型子集產生類型資訊。You cannot use Tlbexp.exe to generate type information for a subset of the types defined in an assembly.

您無法使用 Tlbexp.exe 從已經使用型別程式庫匯入工具 (Tlbimp.exe) 匯入的組件中產生型別程式庫。You cannot use Tlbexp.exe to produce a type library from an assembly that was imported using the Type Library Importer (Tlbimp.exe). 反之,您應該參考使用 Tlbimp.exe 匯入的原始類型程式庫。Instead, you should refer to the original type library that was imported with Tlbimp.exe. 您可以從參考使用 Tlbimp.exe 匯入之組件的組件匯出類型程式庫。You can export a type library from an assembly that references assemblies that were imported using Tlbimp.exe. 請參閱下列範例區段。See the examples section below.

Tlbexp.exe 會將產生的類型程式庫放置在目前的工作目錄或指定給輸出檔的目錄。Tlbexp.exe places generated type libraries in the current working directory or the directory specified for the output file. 單一組件可能導致產生多個類型程式庫。A single assembly might cause several type libraries to be generated.

Tlbexp.exe 會產生類型程式庫但是不會註冊它。Tlbexp.exe generates a type library but does not register it. 這和組件註冊工具 (Regasm.exe) 形成對比,組件註冊工具會產生並註冊型別程式庫。This is in contrast to the Assembly Registration tool (Regasm.exe), which both generates and registers a type library. 若要產生並以 COM 註冊類型程式庫,請使用 Regasm.exe。To generate and register a type library with COM, use Regasm.exe.

如果您未指定 /win32/win64 選項當中的任一項,Tlbexp.exe 會產生與執行編譯的電腦類型 (32 位元或 64 位元電腦) 相對應之 32 位元或 64 位元的類型程式庫。If you do not specify either the /win32 or /win64 option, Tlbexp.exe generates a 32-bit or 64-bit type library that corresponds to the type of computer on which you are performing the compilation (32-bit or 64-bit computer). 為了交互編譯,您可以在 32 位元電腦上使用 /win64 選項以產生 64 位元的類型程式庫,或在 64 位元電腦上使用 /win32 選項以產生 32 位元的類型程式庫。For cross-compilation purposes, you can use the /win64 option on a 32-bit computer to generate a 64-bit type library and you can use the /win32 option on a 64-bit computer to generate a 32-bit type library. 在 32 位元的類型程式庫中,SYSKIND 值會設定為 SYS_WIN32In 32-bit type libraries, the SYSKIND value is set to SYS_WIN32. 在 64 位元的型別程式庫中,SYSKIND 值會設定為 SYS_WIN64In 64-bit type libraries, the SYSKIND value is set to SYS_WIN64. 所有資料類型的轉換資料 (例如,類似 IntPtrUIntPtr 指標大小的資料類型) 都會適當地加以轉換。All data type transformations (for example, pointer-sized data types such as IntPtr and UIntPtr) are converted appropriately.

如果您使用 MarshalAsAttribute 屬性來指定 SafeArraySubTypeVT_UNKOWNVT_DISPATCH 值,則 Tlbexp.exe 會忽略所有後續使用的 SafeArrayUserDefinedSubType 欄位。If you use the MarshalAsAttribute attribute to specify a SafeArraySubType value of VT_UNKOWN or VT_DISPATCH, Tlbexp.exe ignores any subsequent use of the SafeArrayUserDefinedSubType field. 例如,假設有以下的簽章:For example, given the following signatures:

[return:MarshalAs(UnmanagedType.SafeArray, SafeArraySubType=VarEnum.VT_UNKNOWN, SafeArrayUserDefinedSubType=typeof(ConsoleKeyInfo))] public Array StructUnkSafe(){return null;}  
[return:MarshalAs(UnmanagedType.SafeArray, SafeArraySubType=VarEnum.VT_DISPATCH, SafeArrayUserDefinedSubType=typeof(ConsoleKeyInfo))] public Array StructDispSafe(){return null;}  

會產生下列類型程式庫:the following type library is generated:

[id(0x60020004)]  
HRESULT StructUnkSafe([out, retval] SAFEARRAY(IUnknown*)* pRetVal);  
[id(0x60020005)]  
HRESULT StructDispSafe([out, retval] SAFEARRAY(IDispatch*)* pRetVal);  

請注意,Tlbexp.exe 會忽略 SafeArrayUserDefinedSubType 欄位。Note that Tlbexp.exe ignores the SafeArrayUserDefinedSubType field.

由於類型程式庫無法容納這些組件中的所有資訊,因此,Tlbexp.exe 在匯出處理序時可能會捨棄一些資料。Because type libraries cannot accommodate all the information found in assemblies, Tlbexp.exe might discard some data during the export process. 如需轉換處理序的說明並且識別型別程式庫所發出每件資訊的來源,請參閱組件至型別程式庫轉換的摘要For an explanation of the transformation process and identification of the source of each piece of information emitted to a type library, see the Assembly to Type Library Conversion Summary.

請注意,類型程式庫匯出工具會將 TypedReference 參數匯出為 VARIANT 的方法,即使 TypedReference 物件在 Unmanaged 程式碼中不具任何意義。Note that the Type Library Exporter exports methods that have TypedReference parameters as VARIANT, even though the TypedReference object has no meaning in unmanaged code. 當您匯出具有 TypedReference 參數的方法時,類型程式庫匯出工具不會產生警告或錯誤,而使用結果類型程式庫的 Unmanaged 程式碼也將無法正常執行。When you export methods that have TypedReference parameters, the Type Library Exporter will not generate a warning or error and unmanaged code that uses the resulting type library will not run properly.

Microsoft Windows 2000 (含) 以後版本都支援類型程式庫匯出工具。The Type Library Exporter is supported on Microsoft Windows 2000 and later.

範例Examples

下列命令會產生一個和 myTest.dll 中組件同名的類型程式庫。The following command generates a type library with the same name as the assembly found in myTest.dll.

tlbexp myTest.dll  

下列命令會以 clipper.tlb 名稱產生類型程式庫。The following command generates a type library with the name clipper.tlb.

tlbexp myTest.dll /out:clipper.tlb  

下列命令說明使用 Tlbexp.exe 來從組件 (其參考已經使用 Tlbimp.exe 匯入的組件) 中匯出類型程式庫。The following example illustrates using Tlbexp.exe to export a type library from an assembly that references assemblies that were imported using Tlbimp.exe.

先使用 Tlbimp.exe 匯入 myLib.tlb 類型程式庫,然後將它儲存為 myLib.dllFirst use Tlbimp.exe to import the type library myLib.tlb and save it as myLib.dll.

tlbimp myLib.tlb /out:myLib.dll  

下列命令會使用 C# 編譯器來編譯 Sample.dll,,它會參考上一個範例中所建立的 myLib.dllThe following command uses the C# compiler to compile the Sample.dll, which references myLib.dll created in the previous example.

CSC Sample.cs /reference:myLib.dll /out:Sample.dll  

下列命令會產生參考 Sample.dll 之類型程式庫的 myLib.dllThe following command generates a type library for Sample.dll that references myLib.dll.

tlbexp Sample.dll  

請參閱See also