Craig,

Thanks for the information.

Regards,
Mirco

2009/7/15 Craig Ringer <[email protected]>

>
> > I compiled LIBPODOFO.DLL using MinGW.
> > Looking in the DLL the functions underneath are exported. How to use
> > these functions in Delphi ?
>
> You probably can't. Those are C++ exports, not normal C functions, and
> you cannot just call them as C functions.
>
> http://rvelthuis.de/articles/articles-cobjs.html
>
> I quote:
>
> "There is another limitation to what kind of files you can use. You can
> only use object files that are compiled as C files, not C++ files. For
> some reason, the Delphi linker has problems with object files that
> contain C++. This means that your source files must have the extension
> ".c" and not ".cpp". But since you can't use C++ classes directly
> anyway, that is not a severe limitation."
>
> Unless Delphi provides support for interoperating with C++ libraries -
> including ways of instantiating and destroying C++ objects - then you
> most likely have to write a C wrapper around the functions you wish to
> use.
>
> What I recommend is writing your PDF-related code in C++, linking to
> PoDoFo, and providing a C interface to that code. See the example
> (untested) below. I've used C struct wrappers around the void pointers
> to the PoDoFo C++ objects so there's a degree of type-safety in the C
> code, but you can just pass around a bunch of void pointers if you want
> to be really ugly.
>
> Doing this is verbose, ugly, and error-prone. You have to translate C++
> exceptions to C error callbacks / return codes, translate parameters,
> etc. You should also wrap C++ object pointers up in structs that
> C/Delphi can understand so there's a degree of type safety. If you can
> limit the contact points between your Delphi code and PoDoFo to a
> limited set of functions it's not too bad, but the more functions you
> must expose the uglier it gets. Write as much of your PDF-handling code
> as possible in C++ and just pass it the data to add to the PDF via a
> limited set of custom structs.
>
> It's so unpleasant and ugly because Delphi doesn't play well with C++,
> and PoDoFo is a C++ library.
>
> You might write something like:
>
> -- in "my_pdf.h", the C interface to your C++ PoDoFo-using code
>
> #if defined(__cplusplus)
> extern "C" {
> #endif
>
> struct my_pdf {
>  /* Pointer to PoDoFo PdfDocument */
>  void * pdfDocument;
> };
>
> struct my_page {
>  /* Pointer to PoDoFo PdfDocument */
>  void pdfDocument
>  /* Pointer to PoDoFo PdfPage */
>  void * pdfPage;
> };
>
> /* Contents to be added to the page */
> struct page_contents {
>  /* Blah blah - application dependent */
> };
>
> my_pdf * my_pdf_new();
>
> void my_pdf_destroy(my_pdf * document);
>
> void my_pdf_write(my_pdf * document, const char * fn);
>
> my_page * my_pdf_add_page(my_pdf * document, int bottom, int left, int
> width, int height);
>
> void my_pdf_add_page_content(my_page * page, page_contents * contents);
>
> #if defined(__cplusplus)
> }
> #endif
>
>
>
>
> -- In "my_pdf.cxx"
>
> my_pdf * my_pdf_new() {
>  my_pdf * x = NULL;
>  try {
>    x = new my_pdf();
>    x->pdfDocument = static_cast<void*>(new PdfMemDocument());
>  } catch ( const PdfException& e) {
>    /* Handle errors, say with return code or callback */
>  } catch (...) {
>    delete x;
>    return NULL;
>  }
>  return x;
> }
>
> void my_pdf_destroy(my_pdf * document) {
>  delete static_cast<PdfDocument*>(document->pdfDocument);
>  delete document;
> }
>
> void my_pdf_write(my_pdf * document, const char * fn) {
>  PdfMemDocument * doc =
>     static_cast<PdfMemDocument>(document->pdfDocument);
>  try {
>    doc->Write(fn);
>  } catch ( const PdfException& e) {
>    /* Handle errors, say with return code or callback */
>  } catch (...) {
>    /* Handle errors, say with return code or callback */
>  }
> }
>
> my_page * my_pdf_add_page(my_pdf * document, int bottom, int left, int
> width, int height) {
>  my_page * x = NULL;
>  try {
>    x = new my_page();
>    x->pdfDocument = my_pdf->pdfDocument;
>    x->pdfPage = (static_cast<PdfDocument*>(x->pdfDocument))
>                 ->CreatePage( PdfRect(left, bottom, width, height) );
>
>  } catch ( const PdfException& e) {
>    delete x;
>    /* Handle errors, say with return code or callback */
>  } catch(...) {
>    delete x;
>    return NULL;
>  }
>  return x;
> }
>
> void my_pdf_add_page_content(my_page * page, page_contents * contents) {
>  PdfDocument * doc = static_cast<PdfDocument*>(my_page->pdfDocument);
>  try {
>    /* Do your work to populate the page */
>  } catch ( const PdfException& e) {
>    /* Handle errors, say with return code or callback */
>  } catch (...) {
>    /* Handle error, say by invoking a callback or returning an error
>       code */
>  }
> }
>
>
>
> ------------------------------------------------------------------------------
> Enter the BlackBerry Developer Challenge
> This is your chance to win up to $100,000 in prizes! For a limited time,
> vendors submitting new applications to BlackBerry App World(TM) will have
> the opportunity to enter the BlackBerry Developer Challenge. See full prize
> details at: http://p.sf.net/sfu/Challenge
> _______________________________________________
> Podofo-users mailing list
> [email protected]
> https://lists.sourceforge.net/lists/listinfo/podofo-users
>
------------------------------------------------------------------------------
Enter the BlackBerry Developer Challenge  
This is your chance to win up to $100,000 in prizes! For a limited time, 
vendors submitting new applications to BlackBerry App World(TM) will have
the opportunity to enter the BlackBerry Developer Challenge. See full prize  
details at: http://p.sf.net/sfu/Challenge
_______________________________________________
Podofo-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/podofo-users

Reply via email to