10.07.2015 Views

Download - Multivac!

Download - Multivac!

Download - Multivac!

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

2.3 C BindingPDFlib itself is written in the ANSI C language. In order to use the PDFlib C binding, youcan use a static or shared library (DLL on Windows and MVS), and you need the centralPDFlib include file pdflib.h for inclusion in your PDFlib client source modules. Alternatively,pdflibdl.h can be used for dynamically loading the PDFlib DLL at runtime (see nextsection for details).Using PDFlib as a DLL loaded at Runtime. While most clients will use PDFlib as a staticallybound library or a dynamic library which is bound at link time, you can also loadthe PDFlib DLL at runtime and dynamically fetch pointers to all API functions. This is especiallyuseful to load the PDFlib DLL only on demand, and on MVS where the library iscustomarily loaded as a DLL at runtime without explicitly linking against PDFlib. PDFlibsupports a special mechanism to facilitate this dynamic usage. It works according to thefollowing rules:> Include pdflibdl.h instead of pdflib.h.> Use PDF_new_dl( ) and PDF_delete_dl( ) instead of PDF_new( ) and PDF_delete( ).> Use PDF_TRY_DL( ) and PDF_CATCH_DL( ) instead of PDF_TRY( ) and PDF_CATCH( ).> Use function pointers for all other PDFlib calls.> PDF_get_opaque( ) must not be used.> Compile the auxiliary module pdflibdl.c and link your application against it.Note Loading the PDFlib DLL at runtime is supported on selected platforms only.Error Handling in C. PDFlib supports structured exception handling with try/catchclauses. This allows C and C++ clients to catch exceptions which are thrown by PDFlib,and react on the exception in an adequate way. In the catch clause the client will haveaccess to a string describing the exact nature of the problem, a unique exception number,and the name of the PDFlib API function which threw the exception. The generalstructure of a PDFlib C client program with exception handling looks as follows:PDF_TRY(p){...some PDFlib instructions...}PDF_CATCH(p){printf("PDFlib exception occurred in hello sample:\n");printf("[%d] %s: %s\n",PDF_get_errnum(p), PDF_get_apiname(p), PDF_get_errmsg(p));PDF_delete(p);return(2);}PDF_delete(p);PDF_TRY/PDF_CATCH are implemented as tricky preprocessor macros. Accidentally omittingone of these will result in compiler error messages which may be difficult to comprehend.Make sure to use the macros exactly as shown above, with no additional codebetween the TRY and CATCH clauses (except PDF_CATCH( )).An important task of the catch clause is to clean up PDFlib internals using PDF_delete( ) and the pointer to the PDFlib object. PDF_delete( ) will also close the output file if2.3 C Binding 27

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!