Is there a way for common app(CompileAsWinRT is not enabled, just like win32 application) use winrt lib/dll ?

frank zhang 121 Reputation points
2022-05-17T06:52:29.153+00:00

For some reason, I want to use BLE APIs , in Windows::Devices::Bluetooth, whitch seems winrt api. And I make a lib for BLE functions. But when I want to call it as a win32 application, I found that "CompileAsWinRT" should be set in the caller app's vcxproj, Otherwise a "Platform::COMException ^" exception will occured when run winrt APIs?
So is there a way for a common application to use winrt dll/libs?

Universal Windows Platform (UWP)
0 comments No comments
{count} votes

Accepted answer
  1. Castorix31 81,831 Reputation points
    2022-05-17T08:26:57.167+00:00

    It has been simplified with last versions of VS and Windows SDK

    You now just have to do :

    [C++] [Language] [C++ Language Standard] ISO C++17 Standard (/std:c++17)
    [C++] [Language] [Conformance mode] No (/permissive)

    Then

    include  <winrt/base.h>
    

    and you can add the Namespaces you want, like :

    #include  <winrt/windows.devices.bluetooth.h>
    using namespace winrt::Windows::Devices::Bluetooth;
    
    2 people found this answer helpful.
    0 comments No comments

0 additional answers

Sort by: Most helpful