Print Page | Close Window

Using the DLL edition with Delphi

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=3622
Printed Date: 25 Apr 24 at 4:34PM
Software Version: Web Wiz Forums 11.01 - http://www.webwizforums.com


Topic: Using the DLL edition with Delphi
Posted By: HNRSoftware
Subject: Using the DLL edition with Delphi
Date Posted: 21 Oct 18 at 8:31PM
I've been using the Delphi edition since version 7, and just decided to see what the DLL edition looks and acts like.  I was surprised at how little mention there is of the DLL edition in the documentation, and, of what I found, virtually nothing makes sense (to me).

I am using the DLL edition to get a pdf file page count as a test.

After a bit of trial and error, this code works (but it looks nothing like the Delphi example code provided in the documentation).

I placed the dll here: C:\Delphi7\QuickPDF16DLL\DebenuPDFLibraryDLL1611.dll along with the interface pas unit, and added that folder to my library search path

My test program needed to add "DebenuPDFLibraryDLL1611" to the uses statement

const cbDLL16filename00 = 'C:\Delphi7\QuickPDF16DLL\DebenuPDFLibraryDLL1611.dll';
                        // this is where I put it
var QPDF_LicenseKey00   : string = cbMyKey16;   
                        // MUST be set by calling program for anything to work

Function QPDF_GetPageCount00(PDFfn : ansistring) : integer;      
var QP : TDebenuPDFLibraryDLL1611;
var FH : integer;
     begin
     result := 0;
     if FileExists(PDFfn) then
          begin
          QP := TDebenuPDFLibraryDLL1611.Create(cbDLL16filename00);
          try
             if (QP.UnlockKey(QPDF_LicenseKey00) = 1) then
                  begin
                  fh := QP.DAOpenFileReadOnly(PDFfn,'');
                  result := QP.DAGetPageCount(fh);
                  QP.DACloseFile(fh);
                  end;
          finally
             QP.Free;
             end; // of try
          end;
     end;

//---------------------------------------------------------------------------------------

This code performed as expected, and it wound up very close to my VCL code to do the same job.  Aside from the trial-and-error aspect, it was surprisingly easy.

The library load/unload appears to be hidden deeper in the code, since I didn't have to do it myself. I assume the internal code is loading and unloading the dll sensibly.

Howard



Replies:
Posted By: tfrost
Date Posted: 22 Oct 18 at 11:29AM
That's a useful proof of concept, but there is more important guidance in the Getting started document at
http://www.debenu.com/wp-content/uploads/Foxit_Quick_PDF_Library_15_DLL_GettingStarted.pdf" rel="nofollow - https://www.debenu.com/wp-content/uploads/Foxit_Quick_PDF_Library_15_DLL_GettingStarted.pdf

I once considered using the DLL interface in the past but quickly rejected it (for Delphi) because of the difficulty or impossibility of handling string and stream parameters.  I guess that is why there is little mention of using it in a Delphi context.  And by the way it would not make sense to create and free the library for every function call, as in your test, because that would force a load of the DLL each time.


Posted By: HNRSoftware
Date Posted: 22 Oct 18 at 2:25PM
@tfrost - I agree with you totally, but that is actually precisely my point.  My example does not do any explicit load/unload of the dll at all.  It is being done invisibly in the create/free code, without a word mentioned about this in the documentation.  The separate getting started "manual" is just the same couple of pages as in the developers guide.  What I would hope to see in the guide is some performance-related discussion - like - does this really load/unload the library each time? or does it do something else?  Am I supposed to "load" the library at the start of the program, "unload" it at the end, and the create/frees would be able to see that the library is already loaded?  Should I stick that in unit initialization/finalization code? ...

And, yes, the stream part is critical, BUT, the tradeoff is 4Mb of exe file size (the footprint for simply "using" the QuickPDF non-dll edition).  I will add a separate question for how-the-heck do use "DARenderPageToDC".  My gut says that this should be able to render to a bitmap, but my first couple of tries at calling it crashed horribly.  My current work-around is to render a page to jpg file and load the file.


Posted By: HNRSoftware
Date Posted: 22 Oct 18 at 4:00PM
answered my own question on DARenderPageToDC with a little more trial and error.  I had no problem with the parameters FileHandle, PageRef and DPI, but I was trying the bitmap handle for the DC, and what it wanted was the Bitmap.Canvas.handle.  Now it works fine (and fast), and I don't need the stream functionality for this job.  Life is good...


Posted By: tfrost
Date Posted: 23 Oct 18 at 12:16AM
It should be trivial for you to check when your DLL loads and unloads.  Just set a breakpoint and then press control-D on the program in Process Explorer.  But I would be surprised to find that Create did not load the DLL. Also by analogy with all the other QPDF interfaces, why would you want to initialize the whole PDF library and enter your licence key for every different operation you do?

Even if you accept that you only need to initialize (and therefore load) the DLL once at the start of your application, I would never call a DLL load from an initialization section, or a Free from a Finalization. The Windows program loader is not re-entrant and you never know what the VCL is going to do in this area.

I am not concerned with the 'program exe size' issues you mention because our PDF and image processing functions are in our own DLL.  It allows our code to be simple Delphi, and reduces the installer size for the all the programs that call it.  And surely there cannot be much difference in process image size between native Delphi and DLL.


Posted By: HNRSoftware
Date Posted: 23 Oct 18 at 5:18PM
I agree with the initialization/finalization - just wondering where it SHOULD be put.

My point on the dll loading in create it that it bears no resemblance to the documentation on how to use the dll edition.  Obviously it is good that it does it.

The benefit of multiple create/free is that pdf is not central to most of my applications so simple pdf operations like counting pages in a pdf file might be added/removed and I want code that executes reliably, so I minimize the assumptions a program makes about its environment.  If I want to count the pages in 1 file, I can accept the dll loading overhead of a fraction of a second.  If I want to count pages in 1000 files, I use a different function that brackets the whole job in create/free, so the overhead is one load/free for that too.

Mostly I have not been able to detect the load/free overhead, so it can't be much.




Print Page | Close Window

Forum Software by Web Wiz Forums® version 11.01 - http://www.webwizforums.com
Copyright ©2001-2014 Web Wiz Ltd. - http://www.webwiz.co.uk