Is the OCR API supported from Win32 Applications without package identity?

Hill, Tim 21 Reputation points
2020-01-03T15:59:05.933+00:00

I am trying to use the UWP OCR API from a Win32 application. https://learn.microsoft.com/en-us/uwp/api/windows.media.ocr.ocrengine

I've succeeded in actually using it using it from both C#: https://blogs.windows.com/windowsdeveloper/2019/04/30/calling-windows-10-apis-from-a-desktop-application-just-got-easier/
and C++ using C++/WinRT
https://www.nuget.org/packages/Microsoft.Windows.CppWinRT/2.0.191217.1
in a Win32 application.

However, I cannot tell if this is or should be a supported scenario, or whether the documentation is up to date and accurate.

According to:
https://learn.microsoft.com/en-us/windows/apps/desktop/modernize/desktop-to-uwp-supported-api

Windows.Media.Ocr.OcrEngine
Windows.Media.Ocr.OcrLine
Windows.Media.Ocr.OcrResult
Windows.Media.Ocr.OcrWord

are "APIs supported only in apps with package identity". However there is also this vague note:

"Occasionally, APIs in these areas may appear to function correctly. However, if an API is not explicitly listed as supported, you should avoid using it as it may have unintended side effects or behavior. Support for these APIs may become available in future releases. In the interim, your app should use relevant Win32 or .NET APIs instead."

Of course, there are no Win32 OCR apis....

There was a sample app available at some point but it was removed for some reason:
https://github.com/microsoft/cppwinrt/tree/february_2017_refresh/10.0.15042.0/Samples/Ocr

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

1 answer

Sort by: Most helpful
  1. Fay Wang - MSFT 5,196 Reputation points
    2020-01-06T03:27:24.67+00:00

    Hello,

    ​Welcome to Microsoft Q&A!

    From APIs supported only in apps with package identity, OCR API indeed requires package identity. And there are remarks mentioning that it may also take effect in other cases. So according to this document, it's better to package your win32 application into msix mode. Since when you package it in an MSIX package, it will grant package identity to a desktop app.

    0 comments No comments