Back to Articles List

I have a problem with PXC_SignDocumentW in VB.NET

Problem:

I have a problem with PXC_SignDocumentW.

I spent several hours trying to make any of the PXC_SignDocumentXXX functions work.

I have a simple test scenario; create a new PDF document, add a new page and a picture on the page (our intention is to use PDF for e-archiving of scanned documents). Then I add another new page to put the signature on and try to sign the document - which fails.
Without trying to sign the document, I am able to save it and view it in the Adobe Reader.

My 1. approach - using PXC_SignDocumentW

<DllImport("pxclib40")> _
Public Function PXC_SignDocumentW( _
ByVal pdf As Integer _
, ByVal PCertt As IntPtr _
, ByVal page As Integer _
, ByVal rect As PXC_RectF _
, <MarshalAs(UnmanagedType.LPWStr)> ByVal lpwszReason As String _
, <MarshalAs(UnmanagedType.LPWStr)> ByVal lpwszLocation As String _
, <MarshalAs(UnmanagedType.LPWStr)> ByVal lpwszContactInfo As String _
, <MarshalAs(UnmanagedType.LPWStr)> ByVal lpwszImageFile As String _
, ByVal dwFlags As Integer _
) As Integer
End Function

Dim cert As New X509Certificate2("123pass123456.pfx", "123456")
PXC_SignDocumentW( _
myPdfDoc _
, cert.Handle _
, myPage _
, pageSize _
, "test" _
, "anywhere" _
, "test@test" _
, "" _
, 0) _

 fails with an AccessViolationException

Resolution:

The problem was in the PXC_SignDocumentW function declarations: 

where the rectangle should be passed by reference:

ByVal rect As PXC_RectF  ' wrong - does not work
ByRef rect As PXC_RectF  ' works fine

 

<DllImport("pxclib40")> _
Public Function PXC_SignDocumentUsingW( ... )
Was this article helpful?
Yes No Somewhat