C++ UWP 实现
C++ UWP Implementation
所以我一直在做赛车游戏,所以我想添加方向盘支持。我正在使用 UWP(here is the page)。我已经按照 Microsoft 所说的那样将代码添加到 appxmanifest,但我仍然收到错误消息。这是代码:
Input.cpp
#include "pch.h"
#include "Input.h"
#include <vector>
#include <Windows.h>
#include <windows.gaming.input.h>
#include <windows.gaming.input.custom.h>
#include <windows.gaming.input.forcefeedback.h>
Input::Input()
{
}
bool Input::Detect()
{
Windows::Gaming::Input::RacingWheel RacingWheel;
auto Wheels = ref new Vector<RacingWheel^>();
for (auto racingwheel : RacingWheel::RacingWheels)
{
Wheels->Append(racingwheel);
}
};
Input.h
#pragma once
#include <windows.gaming.input.h>
#include <windows.gaming.input.custom.h>
#include <windows.gaming.input.forcefeedback.h>
ref class Input sealed
{
public:
Input();
bool Detect();
private:
void Acquire();
};
报错如下:
RacingWheel::RacingWheels
-Name 后跟 :: 必须是 class 或命名空间
Vector<RacingWheel^>
-预期类型标识符
-需要一个表达式
我是 C++ 的新手,所以非常感谢您的帮助。
您正在混合使用 C++/Cx 和常规 C++。如果您使用 C++ 编写,则不能使用 ref
和 ^
语法,而应该使用常规 COM,如果您使用 C++/Cx 编写,则不需要包含 UWP headers例如 #include <windows.gaming.input.h>
但需要通过创建适当类型的 VS 项目编译为 C++/Cx。
此外,您还需要确保您的目标是 Windows 10 周年纪念版 (10.0.14393),以便 Wheel 可用。
所以我一直在做赛车游戏,所以我想添加方向盘支持。我正在使用 UWP(here is the page)。我已经按照 Microsoft 所说的那样将代码添加到 appxmanifest,但我仍然收到错误消息。这是代码:
Input.cpp
#include "pch.h"
#include "Input.h"
#include <vector>
#include <Windows.h>
#include <windows.gaming.input.h>
#include <windows.gaming.input.custom.h>
#include <windows.gaming.input.forcefeedback.h>
Input::Input()
{
}
bool Input::Detect()
{
Windows::Gaming::Input::RacingWheel RacingWheel;
auto Wheels = ref new Vector<RacingWheel^>();
for (auto racingwheel : RacingWheel::RacingWheels)
{
Wheels->Append(racingwheel);
}
};
Input.h
#pragma once
#include <windows.gaming.input.h>
#include <windows.gaming.input.custom.h>
#include <windows.gaming.input.forcefeedback.h>
ref class Input sealed
{
public:
Input();
bool Detect();
private:
void Acquire();
};
报错如下:
RacingWheel::RacingWheels
-Name 后跟 :: 必须是 class 或命名空间
Vector<RacingWheel^>
-预期类型标识符
-需要一个表达式
我是 C++ 的新手,所以非常感谢您的帮助。
您正在混合使用 C++/Cx 和常规 C++。如果您使用 C++ 编写,则不能使用 ref
和 ^
语法,而应该使用常规 COM,如果您使用 C++/Cx 编写,则不需要包含 UWP headers例如 #include <windows.gaming.input.h>
但需要通过创建适当类型的 VS 项目编译为 C++/Cx。
此外,您还需要确保您的目标是 Windows 10 周年纪念版 (10.0.14393),以便 Wheel 可用。