與非受控程式碼交互操作Interoperating with unmanaged code

.NET Framework 可促進與 COM 元件、COM+ 服務、外部型別程式庫和許多作業系統服務進行的互動。The .NET Framework promotes interaction with COM components, COM+ services, external type libraries, and many operating system services. 資料類型、方法簽章和錯誤處理機制因 Managed 和 Unmanaged 物件模型而有所不同。Data types, method signatures, and error-handling mechanisms vary between managed and unmanaged object models. 為了簡化 .NET Framework 元件與 Unmanaged 程式碼之間的互通性,以及簡化移轉路徑,通用語言執行平台會對用戶端與伺服器隱匿這些物件模型中的差異。To simplify interoperation between .NET Framework components and unmanaged code and to ease the migration path, the common language runtime conceals from both clients and servers the differences in these object models.

在執行階段的控制之下執行的程式碼稱為 Managed 程式碼。Code that executes under the control of the runtime is called managed code. 相反地,在執行階段外部執行的程式碼稱為 Unmanaged 程式碼。Conversely, code that runs outside the runtime is called unmanaged code. COM 元件、ActiveX 介面及 Win32 API 函式都是 Unmanaged 程式碼的範例。COM components, ActiveX interfaces, and Win32 API functions are examples of unmanaged code.

本節內容In this section

將 COM 元件公開給 .NET FrameworkExposing COM Components to the .NET Framework
描述如何從 .NET Framework 應用程式使用 COM 元件。Describes how to use COM components from .NET Framework applications.

將 .NET Framework 元件公開給 COMExposing .NET Framework Components to COM
描述如何從 COM 應用程式使用 .NET Framework 元件。Describes how to use .NET Framework components from COM applications.

使用 Unmanaged DLL 函式Consuming Unmanaged DLL Functions
描述如何使用平台叫用呼叫 Unmanaged DLL 函式。Describes how to call unmanaged DLL functions using platform invoke.

Interop 封送處理Interop Marshaling
描述適用於 COM Interop 和平台叫用的封送處理。Describes marshaling for COM interop and platform invoke.

操作說明:對應 HRESULT 和例外狀況How to: Map HRESULTs and Exceptions
描述例外狀況與 HRESULT 之間的對應。Describes the mapping between exceptions and HRESULTs.

COM 包裝函式COM Wrappers
描述由 COM Interop 所提供的包裝函式。Describes the wrappers provided by COM interop.

類型等價和內嵌 Interop 類型Type Equivalence and Embedded Interop Types
描述如何將 COM 類型的類型資訊內嵌於組件,以及通用語言執行平台如何決定內嵌 COM 類型的對等項。Describes how type information for COM types is embedded in assemblies, and how the common language runtime determines the equivalence of embedded COM types.

如何:使用 Tlbimp.exe 產生主要 Interop 組件How to: Generate Primary Interop Assemblies Using Tlbimp.exe
描述如何使用 Tlbimp.exe (類型程式庫匯入工具) 產生主要 Interop 組件。Describes how to produce primary interop assemblies using Tlbimp.exe (Type Library Importer).

如何:登錄主要 Interop 組件How to: Register Primary Interop Assemblies
描述如何註冊主要 Interop 組件,以便您能在專案中加以參考。Describes how to register the primary interop assemblies before you can reference them in your projects.

免註冊的 COM InteropRegistration-Free COM Interop
描述 COM Interop 如何在不使用 Windows 登錄的情況下啟動元件。Describes how COM interop can activate components without using the Windows registry.

如何:設定免註冊啟用的 .NET Framework 架構 COM 元件How to: Configure .NET Framework-Based COM Components for Registration-Free Activation
描述如何建立應用程式資訊清單,以及如何建立和內嵌元件資訊清單。Describes how to create an application manifest and how to create and embed a component manifest.