当我在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中使用的控件?当我尝试将对象转换为我非常确定它实现的接口时,我遇到了运行时异常.
我有以下接口:
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不支持此类接口
据我所知,这应该是有效的.我正在尝试做什么有问题,或症状是否表明实施问题(某些事情与上述要求不同)?
我正在开发一个metro应用程序,我想创建一些我自己的类将实现的异步操作.
我只找到了使用WinRT操作的异步示例(例如CreateFileAsync).我找不到任何人正在创建异步方法并使用它的情况.
asynchronous microsoft-metro windows-8 windows-runtime c++-cx
WinRT API函数DataPackage::SetStorageItems采用类型的参数IIterable<IStorageItem^>^.我所拥有的是一个单一的StorageItem^,而不是一个集合.
我对如何创建一个IIterable集合感到有点困惑,因为我找不到实现该接口的WinRT集合类.我意识到我可以使用IIterable作为基础创建自己的类,但我的猜测是现有的类我没有看到.
我在这里错过了什么?
我想这很明显,但是:C++,VS11,Win8,Metro.
collections microsoft-metro windows-8 windows-runtime c++-cx
我最近回到了C++.我已经使用C#远离C++/CLI至少一年了,而且我有点生疏了.我正在查看Windows 8的Direct3D应用程序的基本示例,但无法找到解释内容的任何内容
DX::ThrowIfFailed
Run Code Online (Sandbox Code Playgroud)
确实.根据它所说的,如果DirectX中的某些内容失败,它将执行某些操作,但是从实现看起来它似乎用于初始化东西作为Direct3D的基础演示:
Platform::String^ text = "Hello, DirectX!";
DX::ThrowIfFailed(
m_dwriteFactory->CreateTextLayout(
message->Data(),
message->Length(),
m_textFormat.Get(),
700, // maxWidth.
1000, // maxHeight.
&m_textLayout
)
);
Run Code Online (Sandbox Code Playgroud)
有人可以向我解释这个功能是如何工作的.我看到它散落在各个例子中,但谷歌搜索量没有减少适当的文档.提前谢谢你!
在这里,我有一个带有C++ WinRT组件的C#metro app.我需要在WinRT中做一些事情,比如分配照片的名称/路径,并检索照片的缩略图.
首先,我在WinRT C++中编写一个值struct并检索struct array函数,如下所示.
public value struct Item
{
String^ strName;
String^ strPath;
};
public ref class CTestWinRT sealed
{
public:
CTestWinRT();
void TestOutStructArray(Platform::WriteOnlyArray<Item>^ intOutArray)
{
intOutArray->Data[0].strName = ref new String(L"test1.jpg");
intOutArray->Data[0].strPath = ref new String(L"c:\\temp");
intOutArray->Data[1].strName = ref new String(L"test2.jpg");
intOutArray->Data[1].strPath = ref new String(L"c:\\temp");
}
};
Run Code Online (Sandbox Code Playgroud)
然后我在C#按钮中使用TestOutStructArray函数点击如下.
CTestWinRT myNative = new CTestWinRT();
private void btnTestClick(object sender, RoutedEventArgs e)
{
Item[] items = new Item[2];
myNative.TestOutStructArray(items);
}
Run Code Online (Sandbox Code Playgroud)
该函数正常工作,items数组可以通过调试窗口查看值是否正确.
现在,我想在value struct中添加一个字节数组,如下所示.
public value struct Item
{
String^ strName; …Run Code Online (Sandbox Code Playgroud) 根据谷歌的外观,似乎这可能是不可能的,但是:
如何在C++/CX'ref类'中定义'out'参数?
如果您的答案是无法做到的,请提供参考.
是否可以在C++/CX中将byte*转换为Array ^?
目前我通过复制每个值来实现这一点,我知道这不是空间/性能效率.
我目前的实施是:
Array<byte>^ arr = ref new Array<byte>(byteCount);
for (int i = 0; i < byteCount; i++)
{
arr[i] = *(bytes + i);
}
Run Code Online (Sandbox Code Playgroud) 我尝试了以下代码从Universal Windows Platform应用程序发送电子邮件.当我使用EmailMessageBodyKind :: PlainText时,它工作正常.但是,如下面的代码所示,EmailMessageBodyKind :: Html似乎启动了没有内容的电子邮件客户端.有谁知道还需要设置什么才能使其工作 - 文档稀疏8(
using namespace Windows::Storage::Streams;
using namespace Windows::ApplicationModel::Email;
using namespace Windows::Security::Cryptography;
auto bin = CryptographicBuffer::ConvertStringToBinary(
L"<html><body>this <b>is</b> text</body></html>",
BinaryStringEncoding::Utf16LE);
auto memStream = ref new InMemoryRandomAccessStream();
concurrency::create_task(memStream->WriteAsync(bin)).then(
[memStream](unsigned)
{
auto email = ref new EmailMessage();
email->To->Append(ref new EmailRecipient(L"test@gmail.com"));
email->Subject = L"Email Report";
auto randomAccessStreamReference = RandomAccessStreamReference::CreateFromStream(memStream);
email->SetBodyStream(EmailMessageBodyKind::Html, randomAccessStreamReference);
EmailManager::ShowComposeNewEmailAsync(email);
}
);
Run Code Online (Sandbox Code Playgroud) 我正在尝试CoreDispatcher在 Windows Phone 8 上获取 C++ 版本,以便我可以将工作项提交到 UI 线程调度程序,以便我可以更新 UI 线程上的 UI 元素。然而,当我打电话时CoreWindow::GetCurrentForThread(),我就NULL回来了。文档中指出 WP8 支持此功能。只要我获取NULL当前窗口,我就无法Dispatcher从中获取当前;有谁知道如何在 WP8 上获取当前的 Dispatcher?
c++-cx ×10
windows-8 ×3
asynchronous ×1
c# ×1
c++ ×1
casting ×1
collections ×1
email ×1
html ×1
uwp ×1
visual-c++ ×1
winprt ×1