how to make ocr in C++ .net Framework
//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.cpp:
[MTAThreadAttribute]
void Main(array<String^>^ args) {
Application::EnableVisualStyles();
Application::SetCompatibleTextRenderingDefault(false);
//CLR_Test2 is my project name
CLRTest2::Form1 form;
Application::Run(% form);
}
//Test.h:
{
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...
}
}
//Includes and namespaces:
#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;