Access violation
Printed From: Debenu Quick PDF Library - PDF SDK Community Forum
Category: For Users of the Library
Forum Name: I need help - I can help
Forum Description: Problems and solutions while programming with the Debenu Quick PDF Library and Debenu PDF Viewer SDK
URL: http://www.quickpdf.org/forum/forum_posts.asp?TID=1734
Printed Date: 22 Nov 24 at 6:43PM Software Version: Web Wiz Forums 11.01 - http://www.webwizforums.com
Topic: Access violation
Posted By: Kaus Media
Subject: Access violation
Date Posted: 10 Feb 11 at 12:27PM
Hello there, I have an old project which was compiling fine under D2K9 w/ QuickPDF 6. Lately, I have upgraded to D2K10 w/ QuickPDF 7.24ß2 (Tested also 7.14) and I always receive an access violation message which I did not have before with older versions from the RTL library. This message is returned when executing TQuickPDF.Create instruction?! The software has a main program which dynamically load DLLs for various reports, and each of these DLLs are compiled using QuickPDF package in project options. Do you know what causes the trouble? Thanks, Olivier
------------- KMD
|
Replies:
Posted By: Kaus Media
Date Posted: 10 Feb 11 at 1:22PM
I have tried from scratch to create an example of the problem... But I cannot reproduce the problem... ?!
------------- KMD
|
Posted By: Kaus Media
Date Posted: 14 Feb 11 at 3:54PM
Ok. After a long debugging, I have found what's the trouble... And an easy way to reproduce it: procedure TForm1.Button1Click(Sender: TObject);
Var hUserToken: Cardinal; PDF: TQuickPDF; begin If LogonUser ('Administrator','DOMAIN','xxxxxx', LOGON32_LOGON_INTERACTIVE, LOGON32_PROVIDER_DEFAULT, hUserToken) then begin If ImpersonateLoggedOnUser(hUserToken) then begin PDF := TQuickPDF.Create; PDF.Free; end; end; end;
This was working fine with older versions of QuickPDF I was using but with version 7, I cannot impersonate domain admin and perform a TQuickPDF.Create without an "Access violation" message. Any suggestion?
------------- KMD
|
Posted By: Dimitry
Date Posted: 16 Feb 11 at 3:05PM
Hi Kaus,
Did you try impersonation before loading DLL that contains Quick PDF?
Can you please also check does this problem exist if to use Quick PDF Library DLL/ActiveX editions in your DLL?
------------- Regards,
Dmitry
|
Posted By: Kaus Media
Date Posted: 17 Feb 11 at 1:07PM
Hi Dimitri,
Actually it has nothing to do with DLL loading... Sorry I misled you with my first message...
But like I said, after chasing the problem for a few of hours, I was able to reproduce the problem, without any use of DLL nor anything:
Just create from scratch a new VCL EXE project (with a main form)... Drop a standard button on its main from... Paste the code given and link it to the onclick event for the button...
Compile, run, and push the button...
Access Violation at address 004043A1 in module 'Project1'. Read of address 00000008.
Thanks for any help provided ;p
------------- KMD
|
Posted By: Kaus Media
Date Posted: 17 Feb 11 at 1:09PM
Ps: Of course, I use valid domain credentials, you have to adapt the code to your own network...
------------- KMD
|
Posted By: Kaus Media
Date Posted: 21 Feb 11 at 2:53PM
Well... Your suggestion does not work either...I have tried to create the exact same project as described above but using ActiveX instead of VCL component. Project is working perfectly fine without impersonating. But as soon as I add the impersonating instructions, nothing work anymore... procedure TForm1.Button1Click(Sender: TObject); Var hUserToken: Cardinal; begin If LogonUser ('Administrator','DOMAIN','xxxxx', LOGON32_LOGON_INTERACTIVE, LOGON32_PROVIDER_DEFAULT, hUserToken) then begin If ImpersonateLoggedOnUser(hUserToken) then begin PDFLibrary1.UnlockKey(strQuickPDFCode7); PDFLibrary1.DrawText(100, 500, 'Hello from Delphi'); PDFLibrary1.SaveToFile('HelloFromDelphi.pdf'); end; end; end; Error given is now: Project Project1.exe raised exception class EOleSysError with message 'OLE error 80070542, ClassID: {5530475D-F0A2-41BF-AA94-72FA0779289D}
------------- KMD
|
Posted By: Ingo
Date Posted: 21 Feb 11 at 8:06PM
Hi KMD!
If you're using QuickPDF version 7.24 and if you're using Delphi your code should look similar to the following...
uses SysUtils, QuickPDF0724, // . . . var QP : TQuickPDF0724; // . . . try QP := TQuickPDF0724.Create; // . . .
An EOleSysError raises if a class couldn't be registered/ objectcreation failes.
Cheers, Ingo
|
Posted By: Kaus Media
Date Posted: 22 Feb 11 at 9:22AM
Hey Ingo, That's exactly what I mean... TQuickPDF cannot be registered/created with impersonation... Both with VCL component (My first code above) and with ActiveX (The second code above) returns a QuickPDF Create function failure (With either an access violation (VCL) or an EOleSysError (ActiveX)), but ONLY when I impersonate my admin account... See message posted: 14 Feb 11 at 3:54PM. This problem comes with any QuickPDF v7, and was not occuring with older v6... I have strictly, absolutely, no problem to create a QuickPDF object if I don't impersonate: it occurs ONLY with impersonation, and it has nothing to do with DLL loading as I first thought. Please help !!! ;) (I believe I might have to wait for QuickPDF next version...)
------------- KMD
|
Posted By: Kaus Media
Date Posted: 15 Mar 11 at 11:26AM
Still not working with latest 7.24ß4...
------------- KMD
|
Posted By: Ingo
Date Posted: 15 Mar 11 at 2:43PM
So why not asking again on the official support pages?
|
Posted By: Rowan
Date Posted: 31 Mar 11 at 4:35PM
Some potentially relevant information to this topic can be found here:
Delphi Win32 Service “Printer Selected is not valid” error on 2008 64bit standard server. http://stackoverflow.com/questions/4618833/delphi-win32-service-printer-selected-is-not-valid-error-on-2008-64bit-standard - http://stackoverflow.com/questions/4618833/delphi-win32-service-printer-selected-is-not-valid-error-on-2008-64bit-standard
If you're using Windows Vista or Windows 7 you're going to run into issues with security changes they've made recently, UAC being one of them. The above article mentions printing, but it is going to touch on other areas as well. This wasn't a problem in XP.
What operating system are you running on?
|
Posted By: bartvandessel
Date Posted: 09 May 11 at 1:21PM
Hi,
I'm dealing with the same problem. Delphi XE & QuickPdf 7.24. Windows 7 64bit
qp := TQuickPDF0724.Create;
Event Log Delphi: Degub Output, CryptoAcquireContext: Failed to read registry signature value at cryptapi.c line 873
Have you already found a solution?
thx
|
Posted By: Ingo
Date Posted: 09 May 11 at 1:35PM
Hi Bart!
Please have a look at Rowan's post from 31 Mar 11 at 11:35PM.
Cheers and welcome here, Ingo
|
Posted By: mmolenkp
Date Posted: 13 Mar 13 at 8:44PM
My line of code in Delphi 7 was very simple:
rc:=QP.PrintDocument(rc:=QP.PrintDocument, 1, 6, QP.PrintOptions(1, 0, 'Formular'));, 1, 6, QP.PrintOptions(1, 0, 'Formular'));
I get the same kind of error:Invalid printer name.
Much google work done an came on http://www.codenewsfast.com/cnf/article//permalink.art-ng1612q9464 - http://www.codenewsfast.com/cnf/article//permalink.art-ng1612q9464
It seems that the delphi 2007 printer unit:Printer.pas is not designed for Vista and up. The referenced entry give the option to change the source of Printer.pas. On vista it solved my problem.
|
Posted By: Ingo
Date Posted: 13 Mar 13 at 9:35PM
Hi!
First you should try GetPrinterNames to be sure you have the absolutely correct technical printer names in your system. Please keep in mind that the variable for the printer name should be a wide string. I'm still using Delphi 2007 and specially the printer functionalities works and is easy to manage.
Cheers and welcome here, Ingo
|
Posted By: mmolenkp
Date Posted: 13 Mar 13 at 10:06PM
mmolenkp wrote:
My line of code in Delphi 7 was very simple:
rc:=QP.PrintDocument(QP.GetDefaultPrinternam, 1, 6, QP.PrintOptions(1, 0, 'Formular'));, 1, 6, QP.PrintOptions(1, 0, 'Formular'));
I get the same kind of error:Invalid printer name.
Much google work done an came on http://www.codenewsfast.com/cnf/article//permalink.art-ng1612q9464 - http://www.codenewsfast.com/cnf/article//permalink.art-ng1612q9464
It seems that the delphi 2007 printer unit:Printer.pas is not designed for Vista and up. The referenced entry give the option to change the source of Printer.pas. On vista it solved my problem. |
|
Posted By: Ingo
Date Posted: 13 Mar 13 at 10:18PM
Hi!
This isn't "your simple line". This was it: rc:=QP.PrintDocument(rc:=QP.PrintDocument, 1, 6, QP.PrintOptions(1, 0, 'Formular'));, 1, 6, QP.PrintOptions(1, 0, 'Formular')); And btw your second line won't work 'cause the function name is wrong (the missing e) ;-) And again the printer unit in Delphi 2007 works in the described case. I've worked with Delphi 2007 under xp/32 bit, vista 64 bit, win7/32 bit and win7/64 bit.
Cheers, Ingo
|
Posted By: mmolenkp
Date Posted: 13 Mar 13 at 10:23PM
My program was very simpel:
After the modifications made by the mentioned link:
It works only on de default printer, other printers get the message printer not ready
I get the printernames by :QP.GetPrinterNames;
Complete code (77 lines) below
var Form1: TForm1; QP: TQuickPDF0811; QPKEY, prts : STring; UnlockResult, filea, rc : Integer; npn : string; c : pchar;
implementation
{$R *.dfm} procedure TForm1.Button1Click(Sender: TObject); begin Edit3.Text:='Pending'; application.ProcessMessages; UnlockResult := QP.UnlockKey(qpkey); if UnlockResult = 1 then begin If FileExists(edit1.text) = true then begin QP.LOADFROMfILE(edit1.text, ''); filea := QP.SelectedDocument(); rc:=QP.PrintDocument(edit2.text, 1, 6, QP.PrintOptions(1, 1, 'Formular')); end; end; { End of Unlock } edit3.Text:=intTostr(rc); end;
procedure TForm1.ListBox1DblClick(Sender: TObject); begin edit2.Text:=listbox1.Items[listbox1.itemindex]; listbox1.selected[listbox1.Itemindex]:=true; end;
procedure TForm1.ListBox1Click(Sender: TObject); begin edit2.Text:=listbox1.Items[listbox1.itemindex]; listbox1.selected[listbox1.Itemindex]:=true; end;
procedure TForm1.FormCreate(Sender: TObject); begin QPkey:= 'Mykey'; QP := TQuickPDF0811.Create; edit2.text:= QP.GetDefaultPrinterName(); prts:=QP.GetPrinterNames; listbox1.Clear; listbox1.Items.DelimitedText:=prts; listbox1.Itemindex:=listbox1.items.indexof(edit2.text); listbox1.selected[listbox1.Itemindex]:=true; end; end.
|
Posted By: Ingo
Date Posted: 13 Mar 13 at 10:35PM
Hi!
I see edit2.text... Newer versions of QuickPDF need a wide-string! If your technical printer name contains spaces perhpas this could be a second problem.
This is my code and it works very well. PriName is declared as WideString. if ( prname = 'default') Then PriName := QP.GetDefaultPrinterName Else PriName := prname;
propt := QP.PrintOptions(pscal, 0, filename); pc := QP.PageCount; for i := 1 to copies do begin QP.PrintDocument(PriName, 1, pc, propt); end;
|
Posted By: mmolenkp
Date Posted: 14 Mar 13 at 10:02AM
Ik Have declared the printer name as follows : var ws_prtname : WideString;
Ik give no difference.
When i use the default printer.pas I get failure : Invalid printer name.
When I use the modified printer.pas I get failure : Device not ready
I think there must be something wrong in the printer.pas or other units of Delphi 7.
|
Posted By: mmolenkp
Date Posted: 17 Mar 13 at 2:11PM
There is no difference of making changes in string or widestrings definitions.
My system is a Vista 64 bit Sp2 with QPDF 0812.
But I fund a solution for my problem !!!
I Insert the folowing line of code : cPrinter:=qp.NewCustomPrinter(edit2.text);
I can't explain why this is a solution, but it works.
Another strange effect what I have seen is that without that line of code the error "Invalid printername" comes up and after that, QPDF returns on a not expected point in my program.
3 lines of code after the END statement which should be the return point.
So I think there is a failure in the QPDF.PrintDocument error recovery, becuase i am 100% sure that the printer name i use is the right one. I retrieve them by QPDF.Getprinternames;
To solve this last failure I put a Try Except clause around the QPDF.PrintDocument statement..
|
|