Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

calling GdiplusStartup() and GdiplusShutdown() on different dlls

582 views
Skip to first unread message

tfs

unread,
Feb 1, 2010, 10:45:01 AM2/1/10
to
Suppose I develop the following MFC-extended dlls: A.dll, B.dll, C.dll, and
each has exported its own dll-init and dll-release functions. Suppose that
there is an app linking to A.dll and B.dll, and in turn B.dll links to C.dll.

Question:

For A.dll, B.dll, C.dll and even the app, can they call for their own
GdiplusStartup() to obtain their own tokens, and call their own
GdiplusShutdown(), without interfering the gdi+ objs in other dlls?

Reason:

For some dlls I develop, they will be loaded (using AfxLoadLibrary) only
when they are demanded. Therefore if the case described in the question can
work, then I do not need to concern about whether some gdi+ objs will be
invalidated because GdiplusShutdown() is being called somewhere else when
that dll is unloaded.


Dee Earley

unread,
Feb 2, 2010, 4:25:44 AM2/2/10
to
On 01/02/2010 15:45, tfs wrote:
> Suppose I develop the following MFC-extended dlls: A.dll, B.dll, C.dll, and
> each has exported its own dll-init and dll-release functions. Suppose that
> there is an app linking to A.dll and B.dll, and in turn B.dll links to C.dll.
>
> Question:
>
> For A.dll, B.dll, C.dll and even the app, can they call for their own
> GdiplusStartup() to obtain their own tokens, and call their own
> GdiplusShutdown(), without interfering the gdi+ objs in other dlls?

It doesn't say that they can be called multiple times, but seeing as it
returns a token that you have to explicitly shutdown, it implies that
you can.

Normally, Init/Cleanup functions that don't use a token explicitly say
they are reference counted and can be called multiple times.

GdiplusShutdown says "Each call to GdiplusStartup should be paired with
a call to GdiplusShutdown." again implying that you can have multiple
tokens.

--
Dee Earley (dee.e...@icode.co.uk)
i-Catcher Development Team

iCode Systems

tfs

unread,
Feb 2, 2010, 9:28:02 AM2/2/10
to

"Dee Earley" wrote:

> .
>

I looked at the following article from MS:

http://support.microsoft.com/default.aspx/kb/322909

and there is a paragraph, as quoted:

This problem occurs because the CImage class initializes and then shuts down
GDI+ by using the static nested class CInitGDIPlus. This class initializes
GDI+ before any CImage function that requires GDI+ is called. GDI+ is shut
down by calling GdiplusShutdown when the CInitGDIPlus class is destructed.
CInitGDIPlus is a static class that is destructed in a DLL in the context of
DllMain. The documentation states that you cannot call GdiplusShutdown in
DllMain.

As far as I interpret it right, multiple callings of GdiplusStartup() is
allowed, but the corresponding calls of GdiplusShutdown() must be nested. If
that is true, this will be a big trouble for my scenario, because I cannot
control the order of dll-release, even explicitly calling an exported
dll-release function.

For some developers, they experienced app hanging after calling
GdiplusShutdown().

Is GDI+ that horrible?

Christian Kaiser

unread,
Mar 11, 2010, 5:52:01 AM3/11/10
to
> As far as I interpret it right, multiple callings of
> GdiplusStartup() is
> allowed, but the corresponding calls of GdiplusShutdown() must be
> nested. If
> that is true, this will be a big trouble for my scenario, because I
> cannot
> control the order of dll-release, even explicitly calling an
> exported
> dll-release function.
>
> For some developers, they experienced app hanging after calling
> GdiplusShutdown().
>
> Is GDI+ that horrible?


Yes. We also sometimes experience these problems with our add-on
DLLs. You mght consider to ONCE load and initialize GDIPLUS and leave
shutdown to the process cleanup of the OS.

Christian

0 new messages