Can I use ABI::Windows::Media::Ocr in .Net Framework?

sup2MMc 26 Reputation points
2021-08-20T09:56:57.78+00:00

Hi,
some one know how can I use <windows.media.ocr.h> library and ABI::Windows::Media::Ocr in .Net Framework? (C++)
and yes, I saw the sample on microsoft.docs, but that example is on UWP and I need .net framework...

C++
C++
A high-level, general-purpose programming language, created as an extension of the C programming language, that has object-oriented, generic, and functional features in addition to facilities for low-level memory manipulation.
3,559 questions
0 comments No comments
{count} votes

2 answers

Sort by: Most helpful
  1. Castorix31 82,036 Reputation points
    2021-08-20T14:34:31.53+00:00

    In C++/CLI, I can get interfaces with RoActivateInstance, but then it is complicated with async/await...

    But I cannot test with OCR on my PC, I get E_NOTIMPL, while other interfaces like IGeolocator work :

    MTAThreadAttribute must be set for

    HRESULT hr = RoInitialize(RO_INIT_MULTITHREADED);
    

    Main :

    [MTAThreadAttribute]
    void Main(array<String^>^ args) {
        Application::EnableVisualStyles();
        Application::SetCompatibleTextRenderingDefault(false);
        //CLR_Test2 is my project name
        CLRTest2::Form1 form;
        Application::Run(% form);
    }
    

    Test :

    {
        LPCTSTR str = L"Windows.Media.Ocr.OcrEngine";
        HSTRING hstr;
        hr = WindowsCreateString(str, _tcslen(str), &hstr);
        IOcrEngine* pOcrEngine;
        hr = RoActivateInstance(hstr, (IInspectable**)(&pOcrEngine));
        // hr-2147467263     E_NOTIMPL
        WindowsDeleteString(hstr);
        if (FAILED(hr))
        {
            // Error...
        }
    }
    

    At beginning :

    #include <windows.h>
    #include <tchar.h>
    
    #include <roapi.h>
    #include <winstring.h>
    #pragma comment(lib, "windowsapp")
    
    #include <windows.devices.geolocation.h>
    using namespace ABI::Windows::Devices::Geolocation;
    
    #include <windows.media.ocr.h>
    using namespace ABI::Windows::Media::Ocr;
    
    #include <Windows.Foundation.h>
    using namespace ABI::Windows::Foundation;
    
    1 person found this answer helpful.
    0 comments No comments

  2. Guido Franzke 2,196 Reputation points
    2021-08-20T11:51:03.353+00:00

    Hello,
    have a look at this example: OCR
    Regards, Guido