how to use PXCV_Lib36.PXCV_CheckPassword

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

kidzopa
User
Posts: 8
Joined: Fri Sep 17, 2004 5:20 pm

how to use PXCV_Lib36.PXCV_CheckPassword

Post by kidzopa »

if I use the following code which worked in earlier versions, I get a warning with the comparison
res == PXCV_Error.PS_ERR_DocEncrypted stating cannot compare an int to a constant out of range
I looked at the latest PXCView example and the password code is gone

Code: Select all

       
 private bool OpenPDF()
        {
            int res = 0;
            if (DialogResult.OK != openDlg.ShowDialog(this))
                return false;

           res = PXCV_Lib36.PXCV_Init(out m_Doc, "myCode", "mydev");
            if (PXCV_Error.IS_DS_FAILED(res))
	PXCV_Error.ShowDSErrorString(this, res);
            res = PXCV_Lib36.PXCV_ReadDocumentW(m_Doc, openDlg.FileName, 0);
            if (res == PXCV_Error.PS_ERR_DocEncrypted)
            {
                frmPassword dlgPassword = new frmPassword();
                bool bCancel = false;
                do
                {
                    if (DialogResult.OK != dlgPassword.ShowDialog(this))
                        bCancel = true;
                    else
                    {
                        string password = dlgPassword.GetPassword();
                        byte[] bytepass = PXCV_Helper.StringToBytes(password);
                        res = PXCV_Lib36.PXCV_CheckPassword(m_Doc, bytepass, bytepass.Length);
                        if (PXCV_Error.IS_DS_FAILED(res))
                            break;
                    }
                }
                while (!bCancel);
                if (PXCV_Error.IS_DS_SUCCESSFUL(res))
                {
                    res = PXCV_Lib36.PXCV_FinishReadDocument(m_Doc, 0);
                }
            }
            if (PXCV_Error.IS_DS_FAILED(res))
            {
                ClosePDF();
                PXCV_Error.ShowDSErrorString(this, res);
                return false;
            }
            return true;
        }


but if I use this code I get it to work

Code: Select all

byte[] bytepass = PXCV_Helper.StringToBytes("myPwd"); 
			res = PXCV_Lib36.PXCV_ReadDocumentW(m_Doc, openDlg.FileName, 0);
			res = PXCV_Lib36.PXCV_CheckPassword(m_Doc, bytepass, bytepass.Length);
			if (PXCV_Error.IS_DS_SUCCESSFUL(res))
			{
				res = PXCV_Lib36.PXCV_FinishReadDocument(m_Doc, 0);			}
you can always learn -- just listen!!
Corwin - Tracker Sup
User
Posts: 664
Joined: Tue Nov 14, 2006 12:23 pm

Re: how to use PXCV_Lib36.PXCV_CheckPassword

Post by Corwin - Tracker Sup »

Hello,

If you are using latest version of PXCView then you should change old constant

Code: Select all

public const uint PS_ERR_DocEncrypted = 0x820f27ad;
to new:

Code: Select all

public const int PS_ERR_DocEncrypted = unchecked((int)0x821427ad);
Also replace this code:

Code: Select all

string password = dlgPassword.GetPassword();
byte[] bytepass = PXCV_Helper.StringToBytes(password);
res = PXCV_Lib36.PXCV_CheckPassword(m_Doc, bytepass, bytepass.Length);
if (PXCV_Error.IS_DS_FAILED(res))
    break;
by this:

Code: Select all

string password = dlgPassword.GetPassword();
byte[] bytepass = PXCV_Helper.StringToBytes(password);
res = PXCV_Lib36.PXCV_CheckPassword(m_Doc, bytepass, bytepass.Length);
if (PXCV_Error.IS_DS_SUCCESSFUL(res))
    break;
HTH.
kpkemp
User
Posts: 1
Joined: Wed Apr 04, 2007 11:38 pm

Re: how to use PXCV_Lib36.PXCV_CheckPassword

Post by kpkemp »

From what I see the samples use the uint values

I might suggest that the samples be updated it would save us all a lot of irritation
Corwin - Tracker Sup
User
Posts: 664
Joined: Tue Nov 14, 2006 12:23 pm

Re: how to use PXCV_Lib36.PXCV_CheckPassword

Post by Corwin - Tracker Sup »

Hi kpkemp,

In next build constants for error codes will be updated.