Catching Errors/Exceptions under C++ (Borland / Embarcadero)

PDF-XChange Viewer SDK for Developer's
(ActiveX and Simple DLL Versions)

Moderators: PDF-XChange Support, Daniel - PDF-XChange, Chris - PDF-XChange, Sean - PDF-XChange, Vasyl - PDF-XChange, Ivan - Tracker Software, Stefan - PDF-XChange

Prodigy1
User
Posts: 4
Joined: Mon Oct 21, 2013 9:11 pm

Catching Errors/Exceptions under C++ (Borland / Embarcadero)

Post by Prodigy1 »

Good evening. I feel like I am most likely missing something, but I am having one heck of a time trying to figure out how to capture exceptions/errors using the TCoPDFXCview under C++ (imported via TypeLibrary).

Example below. If I don't use the PXCVA_NoUI flag, I get the standard "Error opening document "C:\blah.bla": Error [Operating System]: The system cannot find the file specified.". The problem is when I turn on the NoUI flag. No exceptions are thrown and everything acts as if the document has been opened (obviously except for the fact that imageNum == 0). Is there another call that I'm missing that will return success/failure of the called methods while using the PXCVA_NoUI flag?

I've tried using C++ Builder 5 as well as C++ Builder 2007...same results.

Thx,


long imageNum = 0;
String file2Open = "C:\\blah.bla";
try
{
CoPDFXCview1->OpenDocument(StringToOleStr(file2Open), NULL, &imageNum, PXCVA_NoUI);
}
catch(...)
{
ShowMessage("Error Has Been Caught!");
}
User avatar
Vasyl - PDF-XChange
Site Admin
Posts: 2448
Joined: Thu Jun 30, 2005 4:11 pm

Re: Catching Errors/Exceptions under C++ (Borland / Embarcad

Post by Vasyl - PDF-XChange »

Hi, Prodigy1.

I checked the OpenDocument with/without PXCVA_NoUI. In my C++ test project all works correctly. Without PXCVA_NoUI it shows standard message "...The system cannot find the file specified." for invalid path. With PXCVA_NoUI it returns silently the 0x83F40002 error code (that means the same "The system cannot find the file specified."). Please check our SDK-examples. For example the:
\Program Files\Tracker Software\PDF-XChange Viewer SDK\Examples\CExamples\FullDemo\
works as expected. To try this - launch this example, go to "Document" tab, enable "Without UI" checkbox, type the "c:\\blah.bla" into text-box under "Browse or type file name..." and press the "Open" button on the right. fro me it shows the system's messagebox (note: it is not control's UI, it displayed only by this test-app) with corresponding error message..

HTH.
PDF-XChange Co. LTD (Project Developer)

Please archive any files posted to a ZIP, 7z or RAR file or they will be removed and not posted.
Prodigy1
User
Posts: 4
Joined: Mon Oct 21, 2013 9:11 pm

Re: Catching Errors/Exceptions under C++ (Borland / Embarcad

Post by Prodigy1 »

Thanks for checking into this. The example you pointed me to for MS VisualC++ appears to be correct. The issue however is with the Borland/Embarcadero C++ editions. The .h file that is generated after importing the PDFXCviewAx type library does not show ANY return values on any of the methods (snippet below). All of the methods return void (non of them are returning an HRESULT).

I can attach the generated .h and .cpp files that were generated after importing the type library, if that would help?

// OCX methods
//
void __fastcall DoVerb(BSTR ObjectName/*[in]*/, BSTR OperationName/*[in]*/,
VARIANT DataIn/*[in]*/, VARIANT* DataOut/*[out]*/,
long Flags/*[in,def,opt]*/);
void __fastcall GetTextFromResult(HRESULT Result/*[in]*/, BSTR* Text/*[out]*/);
void __fastcall GetDocumentFromName(BSTR Name/*[in]*/, long* ID/*[out]*/,
long* Eaten/*[in,def,opt]*/);
void __fastcall GetViewObjectFromName(BSTR Name/*[in]*/, long* Type/*[out]*/,
long* ID/*[out]*/, BSTR* ProperName/*[out]*/,
long* Eaten/*[out,def,opt]*/);
void __fastcall OpenDocument(BSTR SourceFileName/*[in]*/,
BSTR OpenPassword/*[in,def,opt]*/,
long* ID/*[out,def,opt]*/, long Flags/*[in,def,opt]*/);
void __fastcall CloseDocument(long ID/*[in]*/, long Flags/*[in,def,opt]*/);
void __fastcall PrintDocument(long ID/*[in]*/, long Flags/*[in,def,opt]*/);
void __fastcall ExportDocument(long ID/*[in]*/, long Flags/*[in,def,opt]*/);
void __fastcall FlushDocument(long ID/*[in]*/, long Flags/*[in,def,opt]*/);
void __fastcall SaveDocument(long ID/*[in]*/, BSTR DestFileName/*[in,def,opt]*/,
long SaveMode/*[in,def,opt]*/, long Flags/*[in,def,opt]*/);
void __fastcall ActivateDocument(long ID/*[in]*/, long Flags/*[in,def,opt]*/);
void __fastcall GetActiveDocument(long* ID/*[out]*/);
void __fastcall GetDocumentsCount(long* Count/*[out]*/);
void __fastcall GetDocumentID(long Index/*[in]*/, long* ID/*[out]*/);
void __fastcall GetDocumentIndex(long ID/*[in]*/, long* Index/*[out]*/);
void __fastcall CloseAllDocuments(long Flags/*[in,def,opt]*/);
void __fastcall ApplyAllCachedChanges(void);
void __fastcall DiscardAllCachedChanges(void);
void __fastcall RunJavaScript(BSTR Script/*[in]*/, BSTR* Result/*[out,def,opt]*/,
long ID/*[in,def,opt]*/, long Flags/*[in,def,opt]*/);
void __fastcall DoDocumentVerb(long ID/*[in]*/, BSTR ObjectName/*[in]*/,
BSTR OperationName/*[in]*/, VARIANT DataIn/*[in]*/,
VARIANT* DataOut/*[out]*/, long Flags/*[in,def,opt]*/);
void __fastcall GetProperty(BSTR Name/*[in]*/, VARIANT* DataOut/*[out]*/,
long Flags/*[in,def,opt]*/);
void __fastcall SetProperty(BSTR Name/*[in]*/, VARIANT DataIn/*[in]*/,
long Flags/*[in,def,opt]*/);
void __fastcall GetDocumentProperty(long ID/*[in]*/, BSTR Name/*[in]*/,
VARIANT* DataOut/*[out]*/,
long Flags/*[in,def,opt]*/);
void __fastcall SetDocumentProperty(long ID/*[in]*/, BSTR Name/*[in]*/,
VARIANT DataIn/*[in]*/, long Flags/*[in,def,opt]*/);
void __fastcall SetDevInfo(BSTR Key/*[in]*/, BSTR Code/*[in]*/);
void __fastcall GetVersionInfo(BSTR* ClientVersion/*[out]*/,
BSTR* ServerVersion/*[out]*/);
void __fastcall LoadSettings(VARIANT DataIn/*[in]*/);
void __fastcall SaveSettings(VARIANT* DataInOut/*[in,out]*/);
User avatar
Vasyl - PDF-XChange
Site Admin
Posts: 2448
Joined: Thu Jun 30, 2005 4:11 pm

Re: Catching Errors/Exceptions under C++ (Borland / Embarcad

Post by Vasyl - PDF-XChange »

Hi, Prodigy1.
All of the methods return void (non of them are returning an HRESULT).

It's normal. This is 'wrapped' import (tip: may be possible other - 'raw' type). In your case you may get error code by:

Code: Select all

try
{
...
}
catch (Error& e) // 
{
    e.code;
}
// I'm not delphi dev - so it is pseudocode, just as idea.
Or may be your IDE have an special option to ignore all exceptions wrapped by try/catch..
HTH.
PDF-XChange Co. LTD (Project Developer)

Please archive any files posted to a ZIP, 7z or RAR file or they will be removed and not posted.
Prodigy1
User
Posts: 4
Joined: Mon Oct 21, 2013 9:11 pm

Re: Catching Errors/Exceptions under C++ (Borland / Embarcad

Post by Prodigy1 »

I am currently using the try/catch and there is nothing to catch. That's the problem. No exceptions are being thrown. I can insert a "throw Exception("blah");" and it does throw an exception so there is nothing preventing exceptions from being thrown...it's simply not happening. Any other ideas/thoughts? We have ported our paperless product to this control, but cannot release it until we can successfully capture any/all errors..

Thx in advance.
User avatar
Ivan - Tracker Software
Site Admin
Posts: 3586
Joined: Thu Jul 08, 2004 10:36 pm

Re: Catching Errors/Exceptions under C++ (Borland / Embarcad

Post by Ivan - Tracker Software »

Exception is not thrown by the ActiveX control itself, it just returns the error code from its own functions.
How this error code is handled depends from where and how you are using it.
In Visual Studio, for example, there are parameters for the #import directive which controls the way error codes are handled.
For example, we have ActiveXDLLName.dll which provides Object with method Method():

If the option raw_interfaces_only is used:

Code: Select all

#import "ActiveXDLLName.dll" raw_interfaces_only
we will get something like a forward declaration:

Code: Select all

struct __declspec(uuid("xxxxxx-....."))
Object : IUnknown
{
    //
    // Raw methods provided by interface
    //

      virtual HRESULT __stdcall Method () = 0;
};
and in case of an error, here you will have only the error code returned by Object::Method() and no exception.

when raw_interfaces_only in not specified, we will have something like this:

Code: Select all

struct __declspec(uuid("xxxxxx-....."))
Object : IUnknown
{
    //
    // Raw methods provided by interface
    //

      virtual HRESULT __stdcall raw_Method () = 0;
      void Method ();
};

inline void Object::Method()
{
  HRESULT hr = raw_Method();
  if (FAILED(hr))
    _com_issue_errorex(hr, this, __uuidof(this));

}
Here you can see the difference.

But as you can also see, it does not depend on the ActiveX control itself, but only the environment where it is used. So, please, refer to the documentation of your C++ Builder and find how to use the ActiveX control there in the way you want. We are not so familiar with Borland C++ Builder to provide you the proper answer.

hth
PDF-XChange Co Ltd. (Project Director)

When attaching files to any message - please ensure they are archived and posted as a .ZIP, .RAR or .7z format - or they will not be posted - thanks.