似乎C++/CX没有StringBuilder类或等价的,所以我认为我们是为了这个而使用STL?
这是我的第一个 C++/CX应用程序.用户在TextBox中输入一些文本,点击ENTER按钮,文本被附加到TextBlock"控制台".这段代码确实有效,但最佳做法是什么?
public ref class MainPage sealed
{
public:
MainPage();
protected:
virtual void OnNavigatedTo(Windows::UI::Xaml::Navigation::NavigationEventArgs^ e) override;
private:
std::wstring _commandLine;
std::wstring _consoleText;
void Button_Click(Platform::Object^ sender, Windows::UI::Xaml::RoutedEventArgs^ e);
};
Run Code Online (Sandbox Code Playgroud)
...
void HelloConsole::MainPage::Button_Click(Platform::Object^ sender, Windows::UI::Xaml::RoutedEventArgs^ e)
{
this->_commandLine = this->InputLine->Text->Data();
this->_commandLine.append(L"\n");
this->_consoleText += this->_commandLine;
this->InputLine->Text = "";
this->OutputConsole->Text = ref new Platform::String(_consoleText.c_str());
}
Run Code Online (Sandbox Code Playgroud) 我一直在尝试使用c ++/cx StorageFile::ReadAsync()来读取商店应用程序中的文件,但它始终返回无效的params异常,无论什么
// "file" are returned from FileOpenPicker
IRandomAccessStream^ reader = create_task(file->OpenAsync(FileAccessMode::Read)).get();
if (reader->CanRead)
{
BitmapImage^ b = ref new BitmapImage();
const int count = 1000000;
Streams::Buffer^ bb = ref new Streams::Buffer(count);
create_task(reader->ReadAsync(bb, 1, Streams::InputStreamOptions::None)).get();
}
Run Code Online (Sandbox Code Playgroud)
我已打开所有清单功能,并为声明添加了"文件打开选取器"+"文件类型关联".有任何想法吗 ?谢谢!
ps:我找到的大多数解决方案都是针对C#,但代码结构类似......
我在WP8应用程序中有一个C++运行时组件,如果我更改命名空间名称,每当我尝试在该命名空间中实例化一个类时,我都会抛出一个"TargetInvocation"异常.
例如,如果我创建默认的C++ Windows运行时组件,标题如下所示:
#pragma once
namespace CppComponent1
{
public ref class WindowsPhoneRuntimeComponent sealed
{
public:
WindowsPhoneRuntimeComponent();
};
}
Run Code Online (Sandbox Code Playgroud)
如果我更改CppComponent1为CppComponent2.h和.cpp,然后尝试WindowsPhoneRuntimeComponent在我的C#代码中实例化一个对象,我会收到以下错误:
A first chance exception of type 'System.TypeLoadException' occurred in Unknown Module.
A first chance exception of type 'System.Reflection.TargetInvocationException' occurred in mscorlib.ni.dll
A first chance exception of type 'System.Reflection.TargetInvocationException' occurred in Microsoft.Phone.ni.dll
Run Code Online (Sandbox Code Playgroud)
如何在WP8应用程序中更改本机模块的命名空间?谢谢!
#include<iostream>
#include<string.h>
#include<Windows.h>
.
.
.
using namespace Windows::Networking::Connectivity;
.
.
.
ConnectionProfile^ internetConnectionProfile = NetworkInformation::GetInternetConnectionProfile();
.
.
.
Run Code Online (Sandbox Code Playgroud)
以上是代码,但它显示
error C2653: 'Windows' : is not a class or namespace name
Run Code Online (Sandbox Code Playgroud)
我该怎么办?已设置公共语言运行时支持(/ clr)
我是visual c ++的新手,我有以下代码:
ref class Book sealed
{
public:
Book(std::string title,std::string author,int year);
void setTitle(std::string title);
std::string getTitle() const;
int getYear() const;
void setYear(int year);
void setAuthor(std::string author_);
std::string getAuthor() const;
private:
std::string title_;
std::string author_;
int year_;
};
Run Code Online (Sandbox Code Playgroud)
当我尝试编译它时,我收到以下错误:
{ctor} signature of public member contains native type.我想这是因为我使用的是std :: string而不是Platform :: String,我该如何解决?
如果没有,那么WinRT有自己的垃圾收集器吗?
我问这个是因为我读到了这个:"没有必要管理底层对象的生命周期.当你完成了你已经激活的最后一个类实例时,Windows会释放该对象." 来自MSDN.
我最近在Windows 8上进行了很多实验,使用用C++/CX编写的WinRT组件编写C#XAML Metro风格的应用程序,以获得更好的性能,并使用C#中没有的功能,特别是DirectX.
在我的WinRT组件中从我的应用包中加载资源时,我的应用程序抛出了以下内容:
TestResources.exe中0x0fd58ae3(MSVCR110D.dll)的未处理异常:0xC0000409:0xc0000409.
我试图对新的StorageFile API进行异步调用(Windows :: Storage :: StorageFile :: GetFileFromApplicationUriAsync链接到其他调用来读取文件内容)并使用concurrency :: task.get()同步生成的任务链.
它似乎没有起作用.如果我没有调用concurrency :: task.get()或concurrency :: task.wait(),那么问题就不会发生,但由于我的DirectX代码的编写方式,我需要同步结果.
我想为我的所有视图模型创建一个抽象基类,但是我遇到了可访问性问题,似乎无法浏览错误.这是我的代码示例:
public ref class ViewModelBase {
...
}
public ref class OtherViewModel : ViewModelBase {
...
}
Run Code Online (Sandbox Code Playgroud)
当我将代码定义为上面的状态时,我收到以下错误:
错误C4585:'MyNamespace :: ViewModelBase':WinRT'公共引用类'必须被密封或从现有的未密封类派生
相反,如果我将ViewModelBase设为私有,则会出现此错误:
错误C3213:基类'MyNamespace :: ViewModelBase'比'OtherViewModel'更难访问
这看起来应该非常简单.我究竟做错了什么?
我有一堆这样的线程任务:
create_task(somewinrtasyncfunction()).then([this(variable_that_the_last_task_returned)
{
//task here
return info;
}).then([this](info)
{
//another task here
return status});
Run Code Online (Sandbox Code Playgroud)
status现在我想在任务之外、调用它的函数中使用。我如何访问它?
我是Windows应用程序开发的新手.我已经构建了一个C#app目标,Windows 10桌面和移动平台.我的C#app调用用C++编写的Windows运行时组件(c ++/cx).
我按照这个MSDN链接运行WACK测试.
我的Windows应用程序认证工具包10.0在我的机器上安装.要运行测试,我会执行验证商店应用程序 - >从计算机上已安装应用程序列表中选择我的应用程序.我的应用程序安装在发布模式下.当我运行WACK测试时,支持的API测试失败,如下所示:
API ??0Delegate@Platform@@Q$AAA@XZ in vccorlib140.dll is not supported for this application type. sample.dll calls this API.
API ??0Exception@Platform@@Q$AAA@H@Z in vccorlib140.dll is not supported for this application type. sample.dll calls this API.
API ??0NotImplementedException@Platform@@Q$AAA@XZ in vccorlib140.dll is not supported for this application type. sample.dll calls this API.
API ??0Object@Platform@@Q$AAA@XZ in vccorlib140.dll is not supported for this application type. sample.dll calls this API.
API ?AlignedFree@Heap@Details@Platform@@SAXPAX@Z in vccorlib140.dll is … c++-cx ×10
windows-8 ×4
c++ ×3
visual-c++ ×2
clr ×1
directx ×1
wack ×1
windows ×1
winrt-xaml ×1