Aximp.exe (Windows Form ActiveX 控制項匯入工具)Aximp.exe (Windows Forms ActiveX Control Importer)

ActiveX 控制項匯入工具可以將 ActiveX 控制項在 COM 類型程式庫中的類型定義,轉換成 Windows Form 控制項。The ActiveX Control Importer converts type definitions in a COM type library for an ActiveX control into a Windows Forms control.

Windows Form 只能裝載 Windows Form 控制項,也就是衍生自 Control 的類別。Windows Forms can only host Windows Forms controls — that is, classes that are derived from Control. Aximp.exe 會產生 ActiveX 控制項的包裝函式類別,可以在 Windows Form 上裝載。Aximp.exe generates a wrapper class for an ActiveX control that can be hosted on a Windows Form. 這可讓您使用相同的設計階段支援和程式設計方法論,以適用於其他 Windows Form 控制項。This allows you to use the same design-time support and programming methodology applicable to other Windows Forms controls.

若要裝載 ActiveX 控制項,您必須產生衍生自 AxHost 的包裝函式控制項。To host the ActiveX control, you must generate a wrapper control that derives from AxHost. 這個包裝函式控制項包含基礎 ActiveX 控制項的執行個體。This wrapper control contains an instance of the underlying ActiveX control. 它知道如何與 ActiveX 控制項進行通訊,但是會顯示為 Windows Form 控制項。It knows how to communicate with the ActiveX control, but it appears as a Windows Forms control. 這個產生的控制項會裝載 ActiveX 控制項並公開其屬性、方法和事件,如同這些產生的控制項。This generated control hosts the ActiveX control and exposes its properties, methods, and events as those of the generated control.

此工具會自動與 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

aximp [options]{file.dll | file.ocx}  

備註Remarks

引數Argument 描述Description
filefile 原始程式檔的名稱,包含要轉換的 ActiveX 控制項。The name of the source file that contains the ActiveX control to convert. 檔案引數必須有 .dll 或 .ocx 副檔名。The file argument must have the extension .dll or .ocx.
選項Option 描述Description
/delaysign 指定 Aximp.exe 使用延遲簽署來簽署產生的控制項。Specifies to Aximp.exe to sign the resulting control using delayed signing. 您必須使用 /keycontainer:/keyfile:/publickey: 選項來指定此選項。You must specify this option with either the /keycontainer:, /keyfile:, or /publickey: option. 如需延遲簽署程序的詳細資訊,請參閱延遲簽署組件For more information on the delayed signing process, see Delay Signing an Assembly.
/help 顯示工具的命令語法和選項。Displays command syntax and options for the tool.
/keycontainer: containerName/keycontainer: containerName 使用 containerName 所指定之金鑰容器中的公開/私密金鑰組,以強式名稱簽署產生的控制項。Signs the resulting control with a strong name using the public/private key pair found in the key container specified by containerName.
/keyfile: filename/keyfile: filename 使用 filename 中找到的發行者正式公開/私密金鑰組,以強式名稱簽署產生的控制項。Signs the resulting control with a strong name using the publisher's official public/private key pair found in filename.
/nologo 隱藏 Microsoft 程式啟始資訊顯示。Suppresses the Microsoft startup banner display.
/out: filename/out: filename 指定要建立的組件名稱。Specifies the name of the assembly to create.
/publickey: filename/publickey: filename 使用由 filename 所指定之檔案中找到的公開金鑰,以強式名稱簽署產生的控制項。Signs the resulting control with a strong name using the public key found in the file specified by filename.
/rcw: filename/rcw: filename 使用指定的執行階段可呼叫包裝函式,而不是產生新的執行階段可呼叫包裝函式。Uses the specified runtime callable wrapper instead of generating a new one. 您可以指定多個執行個體。You may specify multiple instances. 目前的目錄用於相對路徑。The current directory is used for relative paths. 如需詳細資訊,請參閱執行階段可呼叫包裝函式For more information, see Runtime Callable Wrapper.
/silent 隱藏顯示成功訊息。Suppresses the display of success messages.
/source 產生 Windows Form 包裝函式的 C# 原始程式碼。Generates C# source code for the Windows Forms wrapper.
/verbose 指定詳細資訊模式;顯示其他進度資訊。Specifies verbose mode; displays additional progress information.
/? 顯示工具的命令語法和選項。Displays command syntax and options for the tool.

Aximp.exe 會一次轉換整個 ActiveX 控制項類型程式庫並產生一組組件,其中包含通用語言執行平台中繼資料,並控制原始類型程式庫中定義之類型的實作。Aximp.exe converts an entire ActiveX Control type library at one time and produces a set of assemblies that contain the common language runtime metadata and control implementation for the types defined in the original type library. 根據下列模式為產生的檔案命名:The generated files are named according to the following pattern:

適用於 COM 類型的 Common Language Runtime Proxy:progid.dllcommon language runtime proxy for COM types: progid.dll

適用於 ActiveX 控制項的 Windows Forms Proxy (其中 Ax 代表 ActiveX):Axprogid.dllWindows Forms proxy for ActiveX controls (where Ax signifies ActiveX): Axprogid.dll

注意

如果 ActiveX 控制項的成員名稱符合 .NET Framework 中定義的名稱,則 Aximp.exe 在建立 AxHost 衍生類別時就會在成員名稱前面加上 "Ctl"。If the name of a member of the ActiveX control matches a name defined in the .NET Framework, Aximp.exe will prefix the member name with "Ctl" when it creates the AxHost derived class. 例如,如果您的 ActiveX 控制項有一個名為 "Layout" 的成員,它在 AxHost 衍生類別中就會被重新命名為 "CtlLayout",因為 Layout 事件是在 .NET Framework 中定義的。For example, if your ActiveX control has a member named "Layout," it is renamed "CtlLayout" in the AxHost derived class because the Layout event is defined within the .NET Framework.

您可以使用 Ildasm.exe (IL 反組譯工具) 這類工具,檢查這些產生的檔案。You can examine these generated files with tools such as Ildasm.exe (IL Disassembler).

不支援使用 Aximp.exe 來產生 ActiveX WebBrowser 控制項 (shdocvw.dll) 的 .NET 組件。Using Aximp.exe to generate a .NET assembly for the ActiveX WebBrowser control (shdocvw.dll) is not supported.

當您在 shdocvw.dll 上執行 Aximp.exe 時,必定會在執行這個工具的目錄中建立另一個名為 shdocvw.dll 的檔案。When you run Aximp.exe over shdocvw.dll, it will always create another file named shdocvw.dll in the directory from which the tool is run. 如果這個產生的檔案是置於 Documents and Settings 目錄中,它將會對 Microsoft Internet Explorer 和 Windows 檔案總管造成問題。If this generated file is placed in the Documents and Settings directory, it causes problems for Microsoft Internet Explorer and Windows Explorer. 當電腦重新開機時,Windows 會在搜尋 system32 目錄之前,先在 Documents and Settings 目錄中尋找 shdocvw.dll 的複本。When the computer is rebooted, Windows looks in the Documents and Settings directory before the system32 directory to find a copy of shdocvw.dll. 它會使用在 Documents and Settings 目錄中找到的複本,並嘗試載入 Managed 包裝函式。It will use the copy it finds in Documents and Settings and attempt to load the managed wrappers. Internet Explorer 和 Windows 檔案總管將無法正常運作,因為它們必須依賴位於 system32 目錄中之 shdocvw.dll 版本中的轉譯引擎。Internet Explorer and Windows Explorer will not function properly because they rely on the rendering engine in the version of shdocvw.dll located in the system32 directory. 如果發生這種問題,請刪除 Documents and Settings 目錄中的 shdocvw.dll 複本,然後重新啟動電腦。If this problem occurs, delete the copy of shdocvw.dll in the Documents and Settings directory and reboot the computer.

使用 Aximp.exe 搭配 shdocvw.dll 來建立用於應用程式開發的 .NET 組件時,可能也會導致問題。Using Aximp.exe with shdocvw.dll to create a .NET assembly for use in application development can also cause problems. 在這種情況下,您的應用程式將會載入 shdocvw.dll 的系統版本和產生的版本,而且系統版本具有優先權。In this case, your application will load both the system version of shdocvw.dll and the generated version, and may give the system version priority. 在這個情況下,當您試圖將 Web 網頁載入到 WebBrowser ActiveX 控制項內部時,系統會以 [開啟/儲存] 對話方塊提示使用者。In this case, when you attempt to load a Web page inside the WebBrowser ActiveX control, users may be prompted with an Open/Save dialog box. 當使用者按一下 [開啟] 時,將會在 Internet Explorer 中開啟網頁。When the user clicks Open, the Web page will be opened in Internet Explorer. 這種情形只會在使用執行 Internet Explorer 第 6 版 (含) 以前版本的電腦上發生。This occurs only with computers that are running Internet Explorer version 6 or earlier. 若要避免這個問題,請使用受控 WebBrowser 控制項或使用 Visual Studio 來產生受控 shdocvw.dll,如以下連結所述:如何:將參考新增至類型程式庫To prevent this problem, use the managed WebBrowser control or use Visual Studio to generate the managed shdocvw.dll as described in How to: Add References to Type Libraries.

範例Example

下列命令會產生 Media Player 控制項 msdxm.ocx 的 MediaPlayer.dll 和 AxMediaPlayer.dll。The following command generates MediaPlayer.dll and AxMediaPlayer.dll for the Media Player control msdxm.ocx.

aximp c:\systemroot\system32\msdxm.ocx  

另請參閱See also