#1 2019-11-21 11:19:43

swestner
Member
Registered: 2011-07-11
Posts: 8

SynopsePDf in a DLL

Hello,

in the synpdf.pas in

initialization
  {$ifdef USE_SYNGDIPLUS}
  // initialize the Gdi+ library if necessary
  if Gdip=nil then
    Gdip := TGDIPlus.Create('gdiplus.dll');
  {$endif}

the GDIPlus is created when the define is set.

This leads to trouble if the unit is used in a DLL since windows does not allow to initialize and deinitialize the gdiplus in dllmain ("Do not call GdiplusStartup or GdiplusShutdown in DllMain or in any function that is called by DllMain. If you want to create a DLL that uses GDI+, you should use one of the following techniques to initialize GDI+:", https://docs.microsoft.com/en-us/window … usstartup)

Two questions:
1. What is the reason for synpdf to use GDI+? Which functiosn depends on GDI+?
2. If GDI+ is essential needed for some functions then how could the code be changed to allow the usage in a DLL?

Greetings

Stefan

Offline

#2 2019-11-21 12:16:42

ab
Administrator
From: France
Registered: 2010-06-21
Posts: 14,661
Website

Re: SynopsePDf in a DLL

IIRC, it is for PNG and JPEG support - since it is faster than Delphi's corresponding libraries.

You can disabled GDI+ by defining the NO_USE_SYNGDIPLUS conditional in your project.

As clearly stated by the code, by the way:

{$define USE_SYNGDIPLUS}
{ - if defined, the PDF engine will use SynGdiPlus to handle all
    JPG, TIF, PNG and GIF image types (prefered way, but need XP or later OS)
  - if you'd rather use the default jpeg unit (and add some more code to your
    executable), undefine this conditional }
{$ifdef NO_USE_SYNGDIPLUS}
  { this special conditional can be set globaly for an application which doesn't
    need the SynGdiPlus features (like TMetaFile drawing), and would rather
    use the default jpeg unit }
  {$undef USE_SYNGDIPLUS}
{$endif}

Offline

#3 2019-11-21 12:24:34

swestner
Member
Registered: 2011-07-11
Posts: 8

Re: SynopsePDf in a DLL

And the speed of the functions is the only difference? No other functional differences?

If so I comment the usage of GDIPLus out by {.$define USE_SYNGDIPLUS}

But in spite of this I think the way SynPDF initialize the GDI+ should be changed (not inizialize it in initialization-part but when it first uses it)

Offline

#4 2019-11-21 15:50:39

ab
Administrator
From: France
Registered: 2010-06-21
Posts: 14,661
Website

Re: SynopsePDf in a DLL

Offline

#5 2019-11-22 00:29:37

swestner
Member
Registered: 2011-07-11
Posts: 8

Re: SynopsePDf in a DLL

But this fix is not enough.

If USE_SYNGDIPLUS is defined in SynPDF then in the uses a

  {$ifdef USE_SYNGDIPLUS}
  SynGdiPlus, // use our GDI+ library for handling TJpegImage and such
  {$else}

is done.

In SynGDIPlus the initialization looks like

initialization
  Windows.InitializeCriticalSection(GdipCS);
{$ifndef NOTSYNPICTUREREGISTER}
  Gdip.RegisterPictures; // will initialize the Gdip library if necessary
//  GdipTest('d:\Data\Pictures\Sample Pictures\Tree.jpg');
{$endif}

and the RegisterPictures Creates the GDIPLus and we have the same problem again (Init of GDIPlus in dllmain).

This must be changed too. How?

Offline

#6 2019-11-22 07:57:03

ab
Administrator
From: France
Registered: 2010-06-21
Posts: 14,661
Website

Re: SynopsePDf in a DLL

Define NOTSYNPICTUREREGISTER conditional for your project.

Offline

#7 2019-11-22 18:46:48

swestner
Member
Registered: 2011-07-11
Posts: 8

Re: SynopsePDf in a DLL

That's a possible solution but this means that I could not use precompiled DCUs in the IDE because I have ActiveX-DLLs, In-Proc-COM-Server-DLLs and normal EXEs.

In my opinion the best solution would be if the component take care of if running in a DLL and do the RegisterPictures somewhere else in code if this would be possible.

Offline

Board footer

Powered by FluxBB