使用WinRT的原生C ++桌面应用程序:可能吗? [英] native C++ Desktop App using WinRT: possible ?

查看:67
本文介绍了使用WinRT的原生C ++桌面应用程序:可能吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好,我想使用Visual Studio 2015rc在Windows 8.1下使用WinRT编程Kinect v2的漂亮,面向对象的方式。

Hello, i would like to use the nice, object oriented way of programming the Kinect v2 using WinRT under Windows 8.1 using Visual Studio 2015rc.

我设法设置了一个带控制台的桌面项目,可以使用   

I managed to set up a desktop project having a console and can print something to it using    

平台::详细信息::控制台:: WriteLine("欢迎使用WinRT");

Platform::Details::Console::WriteLine("Welcome to WinRT");

但是我尽快调用" KinectSensor ^ sensor = KinectSensor :: GetDefault();"

but as soon as i call "KinectSensor^ sensor = KinectSensor::GetDefault();"

我收到错误消息:"Platform :: ClassNotRegisteredException"

i get the error message: "Platform::ClassNotRegisteredException"

可以这样使用Kinect v2,还是只能将WinRT和C ++ / CX用作Windows8应用程序?

is it possible to use the Kinect v2 that way, or is it only possible to use WinRT and C++/CX it as an Windows8 app ?

使用命名空间Windows :: Globalization;

使用命名空间平台;

使用命名空间WindowsPreview :: Kinect;

使用命名空间Windows :: Foundation ; $
使用命名空间Windows :: Foundation :: Collections;



int main(Array< String ^> ^ args)

{

    

#ifdef __cplusplus_winrt

    // C ++ / CX特定代码在这里...

using namespace Windows::Globalization;
using namespace Platform;
using namespace WindowsPreview::Kinect;
using namespace Windows::Foundation;
using namespace Windows::Foundation::Collections;

int main(Array<String^>^ args)
{
    
#ifdef __cplusplus_winrt
    // C++/CX specific code goes here...

    平台::详情::控制台:: WriteLine("欢迎使用WinRT");

    Platform::Details::Console::WriteLine("Welcome to WinRT");

   矢量<诠释> v {1,2,3,4,5};

 

     // copy std :: vector

     Array< int> ^ arr = ref new Array< int>(& v [0],v.size());



     for(unsigned int i = 0; i< arr-> Length; ++ i)

   &NBSP;&NBSP;&NBSP;   cout<< arr [i]<<结束;



    KinectSensor ^ sensor = KinectSensor :: GetDefault();

     sensor-> Open();

     auto reader = sensor-> ColorFrameSource-> OpenReader();



     while(1)

     {

   &NBSP;&NBSP;&NBSP;   auto frame = reader-> AcquireLatestFrame();

   &NBSP;&NBSP;&NBSP;   if(frame!= nullptr)

   &NBSP;&NBSP;&NBSP;   {

   &NBSP;&NBSP;&NBSP; &NBSP;&NBSP;&NBSP;   auto s = frame-> RelativeTime.ToString();

   &NBSP;&NBSP;&NBSP; &NBSP;&NBSP;&NBSP;   auto tmp =  s->数据();

   &NBSP;&NBSP;&NBSP; &NBSP;&NBSP;&NBSP;   wcout<< tmp<<结束;

   &NBSP;&NBSP;&NBSP;  }

    }
$


#endif

 返回0;

}

    vector<int> v{ 1,2,3,4,5};
 
    // copy std::vector
    Array<int>^ arr = ref new Array<int>(&v[0], v.size());

    for (unsigned int i = 0;i < arr->Length;++i)
        cout << arr[i] << endl;

    KinectSensor^ sensor = KinectSensor::GetDefault();
    sensor->Open();
    auto reader = sensor->ColorFrameSource->OpenReader();

    while (1)
    {
        auto frame = reader->AcquireLatestFrame();
        if (frame != nullptr)
        {
            auto s = frame->RelativeTime.ToString();
            auto tmp =  s->Data();
            wcout << tmp << endl;
        }
    }

#endif
  return 0;
}

推荐答案

您可以使用COM api(参见桌面应用程序中的D2D示例)。虽然在桌面应用程序中有使用WinRT组件的方法,但不支持Kinect v2 api。
You can use the COM api's(see the D2D samples) in Desktop app. While there are ways of using the WinRT components in desktop applications Kinect v2 api's are not supported.


这篇关于使用WinRT的原生C ++桌面应用程序:可能吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆