Attila Szász
Attila Szász

Reputation: 747

Can't use winscard.h in a UWP app due to WINAPI_PARTITION_DESKTOP blocks

I'm developing in C++ a Universal Windows Platform app. I have a working project in C++ which can communicate with smart cards. For this communication it uses the winscard.h library.

I'd like to use in the UWP app this functions provided by the winscard.h, but I can't compile it in the UWP. After some research I found that in this header file there is a condition:

#if WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_DESKTOP)

So this is the reason the compiler doesn't found the methods. Going forward I wanted to change this WINAPI_FAMILY_PARTITION to the WINAPI_PARTITION_DESKTOP but I found nothing about this.

I set in the appxmanifest file the TargetDeviceFamily name to Windows.Desktop, but it doesn't help.

So, my questions are:

  1. Is it possible to change the WINAPI_FAMILY_PARTITION? If not:
  2. Can I use the winscard.h lib in UWP app?

Upvotes: 3

Views: 647

Answers (1)

Peter Torr
Peter Torr

Reputation: 12019

The WINAPI_PARTITION_DESKTOP guard means the API is not supported for UWP apps. It is trivial to unblock the compiler, but it's not a good idea.

  • You could unblock the compiler by making the declarations visible, but then you'd have problems linking.
  • You could manually add the correct import lib to link, but then it would likely fail at runtime due to security checks.
  • Even if you managed to make that work, your app would not be allowed in the Windows Store.
  • Even if you get it working and don't care about the Windows Store, this is not a supported scenario and could break at any point in time.

The correct way to do this is with the types in the Windows.Devices.SmartCards namespace. If there are features missing from that API, you can send feedback via UserVoice or the Feedback Hub.

Upvotes: 4

Related Questions