-
Notifications
You must be signed in to change notification settings - Fork 19
Expand file tree
/
Copy pathMain.cpp
More file actions
73 lines (56 loc) · 1.77 KB
/
Main.cpp
File metadata and controls
73 lines (56 loc) · 1.77 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
#include "pch.h"
template <typename T>
T^ to_cx(winrt::Windows::Foundation::IUnknown const& from)
{
return safe_cast<T^>(reinterpret_cast<Platform::Object^>(winrt::get_abi(from)));
}
template <typename T>
T from_cx(Platform::Object^ from)
{
T to{ nullptr };
winrt::check_hresult(reinterpret_cast<::IUnknown*>(from)->QueryInterface(winrt::guid_of<T>(),
reinterpret_cast<void**>(winrt::put_abi(to))));
return to;
}
template <typename T>
T from_abi(::IUnknown* from)
{
T to{ nullptr };
winrt::check_hresult(from->QueryInterface(winrt::guid_of<T>(),
reinterpret_cast<void**>(winrt::put_abi(to))));
return to;
}
namespace cx
{
using namespace Windows::Foundation;
}
namespace winrt
{
using namespace Windows::Foundation;
}
namespace abi
{
using namespace ABI::Windows::Foundation;
};
void sample()
{
winrt::Uri cpp(L"http://moderncpp.com/");
printf("C++/WinRT: %ls\n", cpp.Domain().c_str());
cx::Uri ^ cx = to_cx<cx::Uri>(cpp);
printf("C++/CX: %ls\n", cx->Domain->Data());
winrt::com_ptr<abi::IUriRuntimeClass> ptr = cpp.as<abi::IUriRuntimeClass>();
winrt::hstring domain;
winrt::check_hresult(ptr->get_Domain(put_abi(domain)));
printf("ABI: %ls\n", domain.c_str());
winrt::Uri cpp_from_cx = from_cx<winrt::Uri>(cx);
WINRT_ASSERT(cpp.Domain() == cpp_from_cx.Domain());
WINRT_ASSERT(cpp == cpp_from_cx);
winrt::Uri cpp_from_abi = from_abi<winrt::Uri>(ptr.get());
WINRT_ASSERT(cpp.Domain() == cpp_from_abi.Domain());
WINRT_ASSERT(cpp == cpp_from_abi);
}
int main()
{
winrt::init_apartment();
sample();
}