Page 1 of 1

Unhandled exception inside ocrtools-x64.dll

Posted: Fri Jul 22, 2016 1:22 pm
by eric_hill
I'm using Visual Studio Community 2015 to build a 64-bit app that will OCR some PDF's through a scanning pipeline. I'm getting an unhandled exception during the OCR_LoadW call, and I can't seem to get by it. Short version of the code is:

Code: Select all

int main(int argc, char** argv) {
	if (argc < 3) {
		cout << "Both an input and output file must be specified on the command line" << endl;
		return 0;
	}

	DWORD maxLevel;
	PXODocument doc; ZeroMemory(&doc, sizeof(PXODocument));
	HRESULT r;

	r = OCR_Init(&doc, oldLicense, oldLicenseDev);
	if (IS_DS_FAILED(r)) {
		cout << "Failed to initialize OCR engine" << endl;
		return -1;
	}

	r = OCR_SetCallback(&doc, &ocrCallback, (LPARAM)&maxLevel);
	if (IS_DS_FAILED(r)) {
		cout << "Failed to define callback procedure" << endl;
		return -1;
	}
	
	string src(argv[1]);
	wstring wsrc(src.begin(), src.end());
	r = OCR_LoadW(doc, (LPWSTR)(wsrc.c_str())); // <- Exception occurs here
	if (IS_DS_FAILED(r)) {
		cout << "Unable to load " << argv[1] << endl;
		return -1;
	}
The exception is:

Code: Select all

Exception thrown at 0x000007FED16B104F (ocrtools-x64.dll) in pxpocr.exe: 0xC0000005: Access violation reading location 0x00000F00E90000FE.
Unhandled exception at 0x000007FED16B104F (ocrtools-x64.dll) in pxpocr.exe: 0xC0000005: Access violation reading location 0x00000F00E90000FE.

Re: Unhandled exception inside ocrtools-x64.dll

Posted: Mon Jul 25, 2016 12:45 pm
by eric_hill
Found the issue:

Code: Select all

int main(int argc, char** argv) {
   if (argc < 3) {
      cout << "Both an input and output file must be specified on the command line" << endl;
      return 0;
   }

   DWORD maxLevel;
   PXODocument doc; ZeroMemory(&doc, sizeof(PXODocument));
   HRESULT r;

   r = OCR_Init(&doc, oldLicense, oldLicenseDev);
   if (IS_DS_FAILED(r)) {
      cout << "Failed to initialize OCR engine" << endl;
      return -1;
   }

   r = OCR_SetCallback(&doc, &ocrCallback, (LPARAM)&maxLevel); // Should be doc, not &doc
   if (IS_DS_FAILED(r)) {
      cout << "Failed to define callback procedure" << endl;
      return -1;
   }
   
   string src(argv[1]);
   wstring wsrc(src.begin(), src.end());
   r = OCR_LoadW(doc, (LPWSTR)(wsrc.c_str())); // <- Exception occurs here
   if (IS_DS_FAILED(r)) {
      cout << "Unable to load " << argv[1] << endl;
      return -1;
   }
The compiler doesn't differentiate between a PXODocument and *PXODocument because PXODocument is a void*. You have to turn the compiler warnings up a couple of clicks to get a warning about the mis-use of the pointer.

Re: Unhandled exception inside ocrtools-x64.dll

Posted: Mon Jul 25, 2016 6:50 pm
by Will - Tracker Supp
Hi Eric,

Thanks for the posts - is all working as expected now?

Cheers,