Created
March 29, 2021 19:02
-
-
Save asklar/1d4345aa28aea565e0f313387a449515 to your computer and use it in GitHub Desktop.
Test WinRT boxing/unboxing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include "pch.h" | |
#include <iostream> | |
#include <winrt/Windows.Devices.Input.h> | |
#include <winrt/Windows.UI.Xaml.h> | |
using namespace winrt; | |
using namespace winrt::Windows::Foundation; | |
using namespace winrt::Windows::UI::Xaml; | |
void printType(const IInspectable& ii) { | |
if (ii.try_as<IReference<int32_t>>()) { | |
std::cout << "int32\n"; | |
} | |
else if (ii.try_as<IReference<uint32_t>>()) { | |
std::cout << "uint32\n"; | |
} | |
else if (ii.try_as<IReference<int16_t>>()) { | |
std::cout << "int16\n"; | |
} | |
else if (ii.try_as<IReference<uint16_t>>()) { | |
std::cout << "uint16\n"; | |
} | |
else if (ii.try_as<IReference<int8_t>>()) { | |
std::cout << "int8\n"; | |
} | |
else if (ii.try_as<IReference<uint8_t>>()) { | |
std::cout << "uint8\n"; | |
} | |
else if (ii.try_as<IReference<int64_t>>()) { | |
std::cout << "int64\n"; | |
} | |
else if (ii.try_as<IReference<uint64_t>>()) { | |
std::cout << "uint64\n"; | |
} | |
else if (ii.try_as<IReference<unsigned char>>()) { | |
std::cout << "uchar\n"; | |
} | |
else if (ii.try_as<IReference<bool>>()) { | |
std::cout << "bool\n"; | |
} | |
else if (ii.try_as<IReference<double>>()) { | |
std::cout << "double\n"; | |
} | |
else if (ii.try_as<IReference<hstring>>()) { | |
std::cout << "string\n"; | |
} | |
else { | |
std::cout << "Unknown box!\n"; | |
} | |
} | |
int main() | |
{ | |
auto pdt = winrt::Windows::Devices::Input::PointerDeviceType::Pen; | |
printType(box_value(pdt)); | |
auto ha = winrt::Windows::UI::Xaml::HorizontalAlignment::Right; | |
printType(box_value(ha)); | |
auto at = ApplicationTheme::Light; | |
printType(box_value(at)); | |
auto esm = ElementSoundMode::FocusOnly; | |
printType(box_value(esm)); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment