zoukankan      html  css  js  c++  java
  • UWP C# 调用 C++/CX

    创建一个UWP项目

    然后创建一个通用C++运行时项目

    右键点击C++项目,添加一个C++类

    在头文件中定义一个类

    #pragma once
    
    
    namespace 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++类库 来使用。

  • 相关阅读:
    ubuntu
    long long 的输入输出问题
    hdu 4135 a到b的范围中多少数与n互质(容斥)
    hdu4757 可持续化01字典树+LCA
    E
    bzoj4260 求两个不相交的区间各自异或后相加的最大值。
    hdu4638 问一段区间能组成多少段连续的数
    hdu4637 计算俩运动对象的时间交
    hdu4632 回文子序列
    hdu4635 有向点双
  • 原文地址:https://www.cnblogs.com/gaobw/p/8243053.html
Copyright © 2011-2022 走看看