Hang in uHYGDIPlus.ShutdownGDIPlus from a DLL

Hi

We’re using Hydra from within a (non-visual) DLL written in Delphi 2007. Hydra 4.0 introduces a new uHYGDIPlus unit that causes the host process to hang when it is shut down. This is actually not related to Hydra technology as such, but seems to be due to the fact that GdiplusStartup and GdiplusShutdown in called during uHYGDIPlus unit initialization/finalization (and thus in our case DllMain), contrary to what is stated in the MSDN documentation (http://msdn.microsoft.com/en-us/library/ms534077):

“Do not call GdiplusStartup or GdiplusShutdown in DllMain or in any function that is called by DllMain”

When comparing the Delphi Rad Studio XE2 GDI+ implementation in Winapi.GDIPOBJ to the Hydra uHYGDIPlus the difference is clear: The calls to “GdiplusStartup” and “GdiplusShutdown” is only performed if not IsLibrary is True.

After changing uHYGDIPlus initialization/finalization to the following code the problem was solved:

initialization
if not IsLibrary then //##PATCHED based on source code in Delphi XE2 Winapi.GDIPOBJ
InitGDIPlus;
finalization
if not IsLibrary then //##PATCHED based on source code in Delphi XE2 Winapi.GDIPOBJ
ShutdownGDIPlus;
end.

In our case we have no use for GDI+, but if you still need to call GdiplusStartup or GdiplusShutdown automatically regardless of whether uHYGDIPlus was started from a DLL or not, Mike van der Meulen seems to have an alternative (but from the MDSN perspective, undocumented) approach. See his blog article at http://mikevdm.com/BlogEntry/Key/GdiplusShutdown-Hangs-Mysteriously.

Best regards,
Bernt

Hello, thank you for the report, logged as #54046. This unit is actually used to initialize GDI+ for FireMonkey plugins, and unfortunately we haven’t considered that module manager will be used inside dll itself. We will try Mike van der Meulen solutions, thank you for sharing the link.