C++/CX似乎使得本地C++与C#FAR的接口比使用C++/CLI"层"的当前方法(具有所需的所有复杂性)更容易和更直接.但是我可以在老式的WPF桌面式应用程序中使用C++/CX OUTSIDE WinRT吗?澄清:我的WPF应用程序'包装'旧的Windows32应用程序代码.所以我正在使用本机c ++进行交互,但在同一个应用程序中使用本机c ++,托管C++和c#都很尴尬.
我必须遗漏一些明显的东西,但我不确定是什么.
我已经创建了一个空白的C++ metro应用程序,我刚刚添加了一个我将在我的UI中绑定的模型,但是我遇到了一系列相关的编译错误xamltypeinfo.g.cpp,我不确定我错过了什么.
我的头文件如下所示:
#pragma once
#include "pch.h"
#include "MyColor.h"
using namespace Platform;
namespace CppDataBinding
{
[Windows::UI::Xaml::Data::Bindable]
public ref class MyColor sealed : Windows::UI::Xaml::Data::INotifyPropertyChanged
{
public:
MyColor();
~MyColor();
virtual event Windows::UI::Xaml::Data::PropertyChangedEventHandler^ PropertyChanged;
property Platform::String^ RedValue
{
Platform::String^ get()
{
return _redValue;
}
void set(Platform::String^ value)
{
_redValue = value;
RaisePropertyChanged("RedValue");
}
}
protected:
void RaisePropertyChanged(Platform::String^ name);
private:
Platform::String^ _redValue;
};
}
Run Code Online (Sandbox Code Playgroud)
和我的cpp文件看起来像这样:
#include "pch.h"
#include "MyColor.h"
using namespace CppDataBinding;
MyColor::MyColor()
{
}
MyColor::~MyColor()
{
}
void MyColor::RaisePropertyChanged(Platform::String^ name) …Run Code Online (Sandbox Code Playgroud) 是否可以使用C++/CX中的lambda处理事件?举个例子,将这段代码从C#转换为C++/CX的最佳方法是什么?
this.animation.Completed += (s, e) =>
{
animation.Begin();
};
Run Code Online (Sandbox Code Playgroud) 我把c ++和c ++/cx放在一起有问题.我需要使用FreeType库,但它们对某些变量使用"通用"名称.我还需要启用VC++扩展,因为WinRT应用程序会导致名称冲突(通用是c ++/cx中的关键字)
1>freetype2\include\freetype\freetype.h(1391): error C2059: syntax error : 'generic'
Run Code Online (Sandbox Code Playgroud)
我只在我的项目属性中添加了freetype引用和aditional include目录.
有没有办法解决这个案子?谢谢你的帮助:) Tomas
我一直在开发一个消耗Windows运行时组件(WRC)的Windows Phone应用程序.由非UI线程访问的功能需要使用访问Windows Phone应用程序的回调.
void WControlPointCallback::OnListChange(char *pFriendlyName)
{
// Callback function to access the UI
pCallBack->AlertCaller("Message");
}
Run Code Online (Sandbox Code Playgroud)
最初没有使用Dispatcher它扔了
Platform::AccessDeniedException.
然后我提到了这个,这个和这个.我试图从UI获取Dispatcher.
var dispatcher = Windows.UI.Core.CoreWindow.GetForCurrentThread().Dispatcher;
Run Code Online (Sandbox Code Playgroud)
它扔了System.AccessViolationException.然后我用了
pDispatcher = Windows::UI::Core::CoreWindow::GetForCurrentThread()->Dispatcher;
Run Code Online (Sandbox Code Playgroud)
在C++代码(WRC)中.但这也引发了Platform::AccessDeniedException.
如何在Windows Phone中获取Dispatcher for UI?
我有一个这样的课:
public ref class Test
{
public:
property int MyProperty;
};
Run Code Online (Sandbox Code Playgroud)
这有效.现在我想将MyProperty的实现移动到CPP文件.我得到编译器错误,我执行此操作时已定义属性:
int Test::MyProperty::get() { return 0; }
Run Code Online (Sandbox Code Playgroud)
这个的正确语法是什么?
我以前使用MiniZip(zlib包装器)来解压缩档案.MiniZip不能用于Metro应用程序,因为它在"iowin32.c"中使用了弃用的API - CreateFile()和SetFilePointer().
我认为这将是一个简单的修复,并创建"iowinrt.c"与CreateFile()和SetFilePointer()替换为CreateFile2()和SetFilePointerEx().虽然这样我获得了一个只使用经过批准的Win8 API的MiniZip版本,但它仍然没用 - 我忘记了沙盒.如果我使用FileOpenPicker()选择一个文件并将其路径传递给我修改过的MiniZip,我仍然无法打开它 - CreateFile2()将因"访问被拒绝"而失败.信息.
所以看起来旧的C API用于文件访问,如果现在几乎无用; 我的理解是,为了解决这个问题,我需要使用新的异步文件访问在C++/CX中重新实现我的"iowinrt".还有其他选择吗?我想我在某处看到WinRT确实具有压缩/解压缩功能,但它只适用于单个文件,而不适用于存档.
我需要它在内存中工作的附加要求.
有一会儿,我以为我有一个通过.NET Framework 4.5的解决方案:
我发现了这条关于如何创建可以在C++/CX中使用的.NET类的信息:http: //social.msdn.microsoft.com/Forums/en-US/winappswithnativecode/thread/3ff383d0-0c9f-4a30- 8987-ff2b23957f01
.NET Framework 4.5在System.IO.Compression中包含ZipArchive和ZipArchiveEntry类:http: //msdn.microsoft.com/en-us/library/system.io.compression.ziparchive%28v=vs.110%29.aspx# Y0 http://msdn.microsoft.com/en-us/library/system.io.compression.ziparchiveentry%28v=vs.110%29.aspx#Y0
我以为我可以使用WinMD输出类型创建C#Metro类库,公开ZipArchive和ZipArchiveEntry,然后在我的C++/CX项目中使用它.但是,即使它起作用,也不会在内存中起作用; ZipArchive和ZipArchiveEntry似乎只适用于文件.
当我在WinRT C++/CX项目中创建新控件时[Windows::Foundation::Metadata::WebHostHidden],Visual Studio 2012默认添加class属性.
例:
namespace WindowsRuntimeComponent1
{
[Windows::Foundation::Metadata::WebHostHidden]
public ref class MyUserControl sealed
{
public:
MyUserControl();
};
}
Run Code Online (Sandbox Code Playgroud)
[WebHostHidden]使得该类对WinRT HTML/Javascript项目不可见.这是否意味着我无法在C++/CX中创建可在Javascript中使用的控件?经过多年的缺席而转向C#后,我刚刚回到C++进行与Windows 8/RT相关的游戏项目.
使用生成的Game Project Skeleton,我偶然发现了类似下面的方法签名.谁能告诉我^应该做什么?
Concurrency::task<Platform::Array<byte>^> ReadDataAsync(Platform::String^ filename)
Run Code Online (Sandbox Code Playgroud) 当我尝试将对象转换为我非常确定它实现的接口时,我遇到了运行时异常.
我有以下接口:
public interface class ISMILTimeContainer;
public interface class ISMILSequence : ISMILTimeContainer;
public interface class ISMILParallel : ISMILTimeContainer;
Run Code Online (Sandbox Code Playgroud)
我有以下课程:
ref class TimeContainer : public ISMILTimeContainer;
ref class Sequence : public TimeContainer, ISMILSequence;
ref class Parallel : public TimeContainer, ISMILParallel;
Run Code Online (Sandbox Code Playgroud)
然后,我尝试以下方法:
ISMILTimeContainer^ container = getSequence(); // returns a Sequence^
ISMILSequence^ sequence = static_cast<ISMILSequence^>(container);
Run Code Online (Sandbox Code Playgroud)
这会在运行时抛出异常:
Platform :: InvalidCastException ^在内存位置0x04AFD83C.HRESULT:0x80004002不支持此类接口
据我所知,这应该是有效的.我正在尝试做什么有问题,或症状是否表明实施问题(某些事情与上述要求不同)?