UWP C# 調用 C++/CX

來源:互聯網
上載者:User

標籤:image   使用   int   檔案中   partial   height   項目   c#   include   

建立一個UWP項目

然後建立一個通用C++運行時項目

右鍵點擊C++項目,添加一個C++類

在標頭檔中定義一個類

#pragma oncenamespace ImageFactoryRT{    public ref class ImageSRC sealed    {    private:        Windows::Foundation::Collections::IVector<int>^ colors;        int width;        int height;    public:        ImageSRC();        void LoadImageSRC(Windows::Foundation::Collections::IVector<int>^ mcolors, int mwidth, int mheight);    public:        // int = byte[A] byte[R] byte[G] byte[B]        property Windows::Foundation::Collections::IVector<int>^ Colors        {            Windows::Foundation::Collections::IVector<int>^ get()            {                return colors;            };            void set(Windows::Foundation::Collections::IVector<int>^ s)            {                colors = s;            };        }        property int Width        {            int get()            {                return width;            };            void set(int s)            {                width = s;            };        }        property int Height        {            int get()            {                return height;            };            void set(int s)            {                height = s;            };        }    };    ImageSRC::ImageSRC()    {    }    void ImageSRC::LoadImageSRC(Windows::Foundation::Collections::IVector<int>^ mcolors, int mwidth, int mheight)    {        this->Colors = mcolors;        this->Width = mwidth;        this->Height = mheight;    }}

在cpp檔案中引入

#include "pch.h"
在UWP項目中引入C++項目

在UWP C#中就可以直接使用 C++中定義的類了

    public sealed partial class MainPage : Page    {        public MainPage()        {            this.InitializeComponent();            ImageFactoryRT.ImageSRC imageSRC = new ImageSRC();            List<int> list = new List<int>();            list.Add(3);            list.Add(2);            list.Add(1);            imageSRC.LoadImageSRC(list, 3, 2);            imageSRC.Width = 1;            int h = imageSRC.Height;        }    }

 

這樣做的主要目的是 通過 [標準C++] ==> [C++/CX] ==> [UWP C#] 可以封裝 標準的C++類庫 來使用。通過win10商店審核。

UWP C# 調用 C++/CX

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.