Cancel print dialog gives automation error

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

EzWz
User
Posts: 42
Joined: Mon Oct 10, 2011 9:03 am

Cancel print dialog gives automation error

Post by EzWz »

Hi, I'm using the latest version of the viewer SDK.
When i load a document and use the printdocument function (with UI) the print dialog opens.
When I click the cancel button on the print dialog, i get an automation error (error 34800116 (decimal value)).

I then opened the printdocument sample and tried cancelling the print dialog in the sample. This gives the same results.
This happens in the vb6 code + samples.
When i try the vb.net sample, it gives a "user aborted" messagebox. Is the error in vb6 the equivalent of an abort result? If so, can i compare it with some enumeration of possible results?

Question 1: what is causing the error? Is it my environment somehow (i tried windows 7 and windows xp machines) or is it a bug in the viewersoftware.
Question 2: Is the error supposed to be caught and checked against an enum of possible user choices? If so where can i find a complete sample?
Question 3: If it is a "real" error what is the best way to work around the error, should i ignore this specific number or should i ignore "any" error given by the printdocument method?

Thanks in advance, Erwin

P.S. I am not allowed to read the forum rules topic on page 1, which make's posting rules a bit pointless imho :P
asadatec
User
Posts: 5
Joined: Tue Nov 10, 2009 10:20 am

Re: Cancel print dialog gives automation error

Post by asadatec »

I have the same problem. Because of that I am currently ignoring any error from the print-dialog but that is not a good solution.
Thank You,
Sebastian
User avatar
Vasyl - PDF-XChange
Site Admin
Posts: 2448
Joined: Thu Jun 30, 2005 4:11 pm

Re: Cancel print dialog gives automation error

Post by Vasyl - PDF-XChange »

Hi, guys.

It is not a bug or error in our SDK. By COM standard, the ActiveX-component can return any error code (by HRESULT) from any method or property.
Many clients generates the automation exception in this case. To skip exception generating you must use the try/catch 'brackets' in your app.
For example, in C#:

Code: Select all

try
{
    PDFViewer.PrintDocument(docID, 0);
}
catch (Exception ex)
{
    string errDesc;
    int hres = System.Runtime.InteropServices.Marshal.GetHRForException(ex);
    PDFViewer.GetTextFromResult(hres, out errDesc);
    //
}
In your case, if user pressed the 'cancel' button in print dialog then viewer returns special 'UserBreak' error-code from PrintDocument() call...

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.
EzWz
User
Posts: 42
Joined: Mon Oct 10, 2011 9:03 am

Re: Cancel print dialog gives automation error

Post by EzWz »

Actually, by COM standard any method that raises an error actually means a mistake.
The printdocument method now is a sub (a void method) where it should have been a function, that returns the result of the dialog.
When it raises an error, something went wrong. The user pressing cancel is not something that goes wrong, it is a functionality that should work this way and there for is not a reason to throw an error.
The function should work like the msgbox function by microsoft, that gives a result of "ok", "Cancel", "yes", "no" etc.
This result can be checked against an enumeration of possible - correct - results. (vbmsgboxresult enum).
An error on the other hand is thrown when for example the printer runs out of paper, reports a paperjam or similar errors.

To get back to the problem at hand: if you think i should interpret this error as a "user pressed cancel" than in my "catch block" (which does not exist in that way in vb6) i should exclude this error from any real errors. I.e. i make a clause that says: "if i get any error when executing this printdocument method i should do the errorhandling block (some code that presents the user with a message and maybe log the error etc) EXCEPT for when the err numer equals a number from a list, in which case it is actually normal behaviour and i should not treat it as an error".

Now if you think this is what we should do, then this list is something that should be in the documentation and ideally should also be in a public enum which we can then check against.
So the real question is: what errors (nr's) do you raise from this function and what do they stand for? I can then decide what to do with each of these "errors" in the catch block.
User avatar
Vasyl - PDF-XChange
Site Admin
Posts: 2448
Joined: Thu Jun 30, 2005 4:11 pm

Re: Cancel print dialog gives automation error

Post by Vasyl - PDF-XChange »

Hi, Erwin.
The printdocument method now is a sub (a void method) where it should have been a function, that returns the result of the dialog.
It is a 'void' method in VB/NET/Delphi/etc. clients but is NOT a void method for C++ clients...
The user pressing cancel is not something that goes wrong...
You are right BUT it is the current implementation and we cannot change it right now, please wait for V3...
The function should work like the msgbox function by microsoft, that gives a result of "ok", "Cancel", "yes", "no" etc.
No, this function can return any printing-error, 'printed_successfully' (S_OK) or 'canceled_by_user' (currently - it is error-code, but in the new version we will change it to S_FALSE). The 'printing-error' can be, for example: 'No Printer', 'Invalid Printer', 'Invalid Paper', 'Any-Printer-Specific-Error', etc.

Currently you can use the following code to detect/except the 'canceled_by_user' error by (C++ code):

Code: Select all

#define ERR_USER_BREAK			500
#define ERR_INVALID_PAGES_RANGE	10001
#define ERR_NO_HAVE_PRINTERS		10119
#define ERR_INVALID_PRINTER		10120
#define ERR_PRINT_FAILURE			10121

int GetErrorCode(int err)
{
   if (err >= 0) // isn't a error
     return 0;
   return ((x) & 0x0ffff);
};

bool IsUserBreakError(int err)
{
    return (GetErrorCode(err) == ERR_USER_BREAK);
}
Also our control can return the system's error code (example: ERROR_ACCESS_DENIED(5), ERROR_OUTOFMEMORY(14), etc), wrapped by HRESULT. Test it by:

Code: Select all

bool IsSystemError(in err)
{
     if (err >= 0)
        return false;
     if ((err & 0x02000000) == 0)
        return true;      
     return ((err >> 16) & 0x1ff) == 0x1ff;
}
Look also to IPDFXCview::GetTextFromResult method...

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.
EzWz
User
Posts: 42
Joined: Mon Oct 10, 2011 9:03 am

Re: Cancel print dialog gives automation error

Post by EzWz »

Quite right. But in my case i need a vb6 implementation. That means i will define the error code as a constant and check against that, similar to your first example. So i will be working without a .NET framework.
You define this user_break error as 500, but in vb6 i receive errror 34800116. Apparently this is equivalent??

I found a similar mechanism with the cancel button in the dialog that asks for the password when I open a password protected pdf.
I was hoping you would use the same value for the "cancel" error there, but in that case i receive error 33751540. I presume i have to treat this the same way.
I mention it, because you said you wanted to alter this mechanism in some future version perhaps.
User avatar
Stefan - PDF-XChange
Site Admin
Posts: 19913
Joined: Mon Jan 12, 2009 8:07 am

Re: Cancel print dialog gives automation error

Post by Stefan - PDF-XChange »

Thanks for the follow up EzWz,

We will certainly have your comment in mind when working on altering this behaviour in the future.

I've asked Vasyl to follow up on this and comment on the error codes you get, so there should be a new reply in this topic shortly.

Best,
Stefan
User avatar
Vasyl - PDF-XChange
Site Admin
Posts: 2448
Joined: Thu Jun 30, 2005 4:11 pm

Re: Cancel print dialog gives automation error

Post by Vasyl - PDF-XChange »

Hi, Erwin.
You define this user_break error as 500, but in vb6 i receive errror 34800116. Apparently this is equivalent??
Please use it to extract the real error-code from your VB-error code (34800116, 33751540):

Code: Select all

Private Sub GetErrorCode(vbError As Long) As Long
     GetErrorCode = vbError And &H0FFFF ; in C++, ((vbError) & 0x0ffff)
End Sub
Private Sub IsUserBreakError(vbError As Long) As Boolean
    IsUserBreakError = GetErrorCode(err) = 500
End Sub
Sorry for possible mistakes in code, I'm not a VB6 programmer..

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.
EzWz
User
Posts: 42
Joined: Mon Oct 10, 2011 9:03 am

Re: Cancel print dialog gives automation error

Post by EzWz »

Thanks, I have these issues working correctly now.
Thinking on this, I wonder if there are any other dialogs i didnt see yet, that have this type of cancel (raising an error).
I mean, we handled the print dialog and the password dialog now. Are there any more that i perhaps didnt find yet?

And lastly: i still can't read the forum rules and regulations (don't have the required priviliges) :P
User avatar
Stefan - PDF-XChange
Site Admin
Posts: 19913
Joined: Mon Jan 12, 2009 8:07 am

Re: Cancel print dialog gives automation error

Post by Stefan - PDF-XChange »

Hello EzWz,

Glad to hear that the issue with the discussed buttons is resolved. I can not comment on your new question - so will seek Vasyl's advise.

And I hope I have now fixed your forum permissions and you can finally see the forum rules :D

Best,
Stefan
EzWz
User
Posts: 42
Joined: Mon Oct 10, 2011 9:03 am

Re: Cancel print dialog gives automation error

Post by EzWz »

Tracker Supp-Stefan wrote:Hello EzWz,

Glad to hear that the issue with the discussed buttons is resolved. I can not comment on your new question - so will seek Vasyl's advise.

And I hope I have now fixed your forum permissions and you can finally see the forum rules :D

Best,
Stefan
Permissions work now (at least for me :wink: ) and we ordered the SDK now :D
User avatar
Paul - PDF-XChange
Site Admin
Posts: 7370
Joined: Wed Mar 25, 2009 10:37 pm

Re: Cancel print dialog gives automation error

Post by Paul - PDF-XChange »

HI EzWz,

that's great to hear! Thanks for the update. We are here if you need us as you develop using that SDK.

regards
Best regards

Paul O'Rorke
PDF-XChange Support
http://www.pdf-xchange.com