PHP User Warning: fetch_template() calls should be replaced by the vB_Template class. Template name: bbcode_highlight in ..../includes/functions.php on line 4197
Ways to call GdiplusShutdown-VBForums
Results 1 to 4 of 4

Thread: Ways to call GdiplusShutdown

  1. #1

    Thread Starter
    Frenzied Member wqweto's Avatar
    Join Date
    May 2011

    Ways to call GdiplusShutdown

    Is there a sane way to implement GdiplusStartup/GdiplusShutdown sequence w/o risking stepping on our toes?

    As far as I can tell if developer A and developer B separately implement reference counting on GDI+ usage they still can blow thing up by calling [tt]GdiplusShutdown[/t] out of order like this:

    token1 = GdiplusStartup
    .. work 1
    token2 = GdiplusStartup
    ... work 2
    GdiplusShutdown token1
    ... work 3
    ... this completely fails as GdiplusShutdown has done the damage
    GdiplusShutdown token2
    ... mosty some access violation will be reached before this point

    So is there something that I'm unable to find in the docs? How are we suppoed to initialize GDI+ in a compatible way, w/o support from the VB runtime?

    My proposal for all fellow devs is to completely abandon shutting GDI+ down for any of our processes and to use a one-time initializer -- a simple code like this:
    thinBasic Code:
    1. Option Explicit
    3. Private Declare Function GetModuleHandle Lib "kernel32" Alias "GetModuleHandleA" (ByVal lpModuleName As String) As Long
    4. Private Declare Function GdiplusStartup Lib "gdiplus" (hToken As Long, pInputBuf As Any, Optional ByVal pOutputBuf As Long = 0) As Long
    7. Private Sub Class_Initialize()
    8.     Dim aInput(0 To 3)  As Long
    10.     If GetModuleHandle("gdiplus") = 0 Then
    11.         aInput(0) = 1
    12.         Call GdiplusStartup(0, aInput(0))
    13.     End If
    14.     '--- more init follows
    15.     '...
    16. End Sub
    Ignore the returned token, GDI+ is never to be unloaded.

    Any comments on this proposal too?


  2. #2
    Join Date
    Feb 2006

    Re: Ways to call GdiplusShutdown

    I'm not seeing any such issue, but perhaps I have misinterpreted your scenario?

    Name:  sshot.png
Views: 70
Size:  7.3 KB

    Private Sub Form_Load()
        Dim AP1 As AlphaPic
        Dim AP2 As AlphaPic
        Set AP1 = New AlphaPic
        Set AP2 = New AlphaPic
        AP1.LoadBitmap "Drink.png"
        AP2.LoadBitmap "GhostFace.png"
        AutoRedraw = True
        AP1.Render Me, (ScaleX(ScaleWidth, ScaleMode, vbPixels) - AP1.Width) \ 2
        Set AP1 = Nothing
        AP2.Render Me
        AP2.Render Me, ScaleX(ScaleWidth, ScaleMode, vbPixels) - AP2.Width
        AutoRedraw = False
        Set AP2 = Nothing
    End Sub
    Attached Files Attached Files

  3. #3

    Thread Starter
    Frenzied Member wqweto's Avatar
    Join Date
    May 2011

    Re: Ways to call GdiplusShutdown

    Weird and it works on XP apparently. I was reading some threads on the internet w/o doing my own testing. Most of the horror stories are related to calling startup/shutdown from DllMain.

    As far as I understand there is a background thread involved but it's not clear which Gdip functions actually spawn it. Overlapped nesting could be problematic in this case, more testing needed.


  4. #4
    VB-aholic & Lovin' It LaVolpe's Avatar
    Join Date
    Oct 2007
    Beside Waldo

    Re: Ways to call GdiplusShutdown

    Quote Originally Posted by wqweto View Post
    Most of the horror stories are related to calling startup/shutdown from DllMain.
    And why not?

    Per MSDN:
    Do not call GdiplusStartup or GdiplusShutdown in DllMain or in any function that is called by DllMain.
    That MSDN page goes on to tell people how to write a DLL that will use GDI+
    Insomnia is just a byproduct of, "It can't be done"

    Classics Enthusiast? Here's my 1969 Mustang Mach I Fastback. Her sister '67 Coupe has been adopted

    Newbie? Novice? Bored? Spend a few minutes browsing the FAQ section of the forum.
    Read the HitchHiker's Guide to Getting Help on the Forums.
    Here is the list of TAGs you can use to format your posts
    Here are VB6 Help Files online

    {Alpha Image Control} {Memory Leak FAQ} {Unicode Open/Save Dialog} {Resource Image Viewer/Extractor}
    {VB and DPI Tutorial} {Manifest Creator} {UserControl Button Template} {stdPicture Render Usage}

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts


Click Here to Expand Forum to Full Width