The project I am working on is deployed as a DLL ISAPI Module and as a standalone .exe. I use FlexCel to generate XLS Reports and convert them to PDF. The standalone EXE works fine, while the DLL crashes every time I try to generate PDFs.
implementation
function GdipAlloc; external WINGDIPDLL name 'GdipAlloc' delayed;
procedure GdipFree; external WINGDIPDLL name 'GdipFree' delayed;
function GdiplusStartup; external WINGDIPDLL name 'GdiplusStartup' delayed;
procedure GdiplusShutdown; external WINGDIPDLL name 'GdiplusShutdown' delayed;
function GdipCreatePath; external WINGDIPDLL name 'GdipCreatePath' delayed;
function GdipCreatePath2; external WINGDIPDLL name 'GdipCreatePath2' delayed;
Indeed, the problem is with the initialiation of GDI+. The problem is not that GDI+ is a dll (that's just the way it is, you can't link it, but it is a part of the OS). The problem is that you can't init gdi+ from DLLMain, and the initialization sections of delphi are called in DLLMain, So our code is like this:
Export your own startup function that calls GdiplusStartup and your own shutdown function that calls <strong ns="http://www.w3.org/1999/">GdiplusShutdown</strong>. Require your clients to call your startup function before they call other functions in your DLL and to call your shutdown function when they have finished using your DLL.
And create your own GetExtensionVersion method which calls the GetExtensionVersion method in ISApiApp, but also calls FlexCelDllInit. Then export that method instead of the one it is exported.
But also note: for cases where you don't have any init method, or if you don't want to mess with GetExtensionVersion/OnTerminate, you can just call FlexCelDllInit/ShutDown in your app before and after using FlexCel every time. Those are fast methods anyway, so it won't really matter: