共用方式為


CLR 整合 (C++/CX)

某些 Windows 執行階段 類型會以 C++/CX 接收特殊處理,以及以 Common Language Runtime (CLR) 為基礎的語言。 這篇文章討論一種語言的數個類型如何對應到另一種語言。 例如,CLR 將 Windows.Foundation.IVector 對應到 System.Collections.IList、將 Windows.Foundation.IMap 對應到 System.Collections.IDictionary 等等。 同樣地,C++/CX 特別對應平臺::D elegate 和 Platform::String 等類型。

將 Windows 執行階段 對應至 C++/CX

C++/CX 讀取 Windows 元數據 (.winmd) 檔案時,編譯程式會自動將一般 Windows 執行階段 命名空間和類型對應至C++/CX 命名空間和類型。 例如,數值 Windows 執行階段 類型UInt32會自動對應至 default::uint32

C++/CX 會將數個其他 Windows 執行階段 類型對應至 Platform 命名空間。 例如,代表只讀 Unicode 文字字串的 Windows::Foundation HSTRING 句柄會對應至C++/CX Platform::String 類別。 當 Windows 執行階段 作業傳回錯誤 HRESULT 時,它會對應至 C++/CX Platform::Exception

C++/CX 也會對應 Windows 執行階段 命名空間中的特定類型,以增強型別的功能。 針對這些類型,C++/CX 提供C++專屬的協助程式建構函式和方法,而且無法在類型的標準 .winmd 檔案中使用。

下列清單顯示支援新建構函式和 Helper 方法的值結構。 如果之前撰寫的程式碼使用結構初始設定清單,請變更為使用新加入的建構函式。

Windows::Foundation

  • Point

  • [週框]

  • 大小

Windows::UI

  • Color

Windows::UI::Xaml

  • CornerRadius

  • 期間

  • GridLength

  • Thickness

Windows::UI::Xaml::Interop

  • TypeName

Windows::UI::Xaml::Media

  • 矩陣

Windows::UI::Xaml::Media::Animation

  • KeyTime

  • RepeatBehavior

Windows::UI::Xaml::Media::Media3D

  • Matrix3D

將 CLR 對應至 C++/CX

當Microsoft C++或 C# 編譯程式讀取 .winmd 檔案時,它們會自動將元數據檔中的特定類型對應至適當的C++/CX 或 CLR 類型。 例如,在 CLR 中,IVector<T> 介面會對應至 IList<T>。 但在 C++/CX 中,IVector<T> 介面不會對應至另一種類型。

Windows 執行階段 中的 IReference<T> 會對應至 .NET 中的可為<Null T>。

另請參閱

與其他語言交互操作