Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. GDI+ initialization

GDI+ initialization

Scheduled Pinned Locked Moved C / C++ / MFC
winformsgraphicsquestion
10 Posts 4 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • I Offline
    I Offline
    indigox3
    wrote on last edited by
    #1

    I've got a class that wraps GDI+. In the constructor I call GdiplusStartup, and in the destructor I call GdiplusShutdown. This could result in multiple startup & shutdown calls. (And possibly several startup calls before any shutdown calls) Is it safe to make these calls multiple times?

    L M L 3 Replies Last reply
    0
    • I indigox3

      I've got a class that wraps GDI+. In the constructor I call GdiplusStartup, and in the destructor I call GdiplusShutdown. This could result in multiple startup & shutdown calls. (And possibly several startup calls before any shutdown calls) Is it safe to make these calls multiple times?

      L Offline
      L Offline
      led mike
      wrote on last edited by
      #2

      indigox3 wrote:

      Is it safe to make these calls multiple times?

      What does the documentation say?

      I 1 Reply Last reply
      0
      • L led mike

        indigox3 wrote:

        Is it safe to make these calls multiple times?

        What does the documentation say?

        I Offline
        I Offline
        indigox3
        wrote on last edited by
        #3

        Not much relevant to my question. http://msdn2.microsoft.com/en-us/library/ms534077.aspx

        L 1 Reply Last reply
        0
        • I indigox3

          I've got a class that wraps GDI+. In the constructor I call GdiplusStartup, and in the destructor I call GdiplusShutdown. This could result in multiple startup & shutdown calls. (And possibly several startup calls before any shutdown calls) Is it safe to make these calls multiple times?

          M Offline
          M Offline
          Mark Salsbery
          wrote on last edited by
          #4

          I don't know.  The docs state: "You must call GdiplusStartup before you create any GDI+ objects, and you must delete all of your GDI+ objects (or have them go out of scope) before you call GdiplusShutdown." Although there's a token associated with each startup/shutdown pair, the token (or any other context) isn't used when working with GDI+ objects.  That means there's no internal context relating created GDI+ objects with a GdiPlusStartup() call. If I had to guess, I'd say it will work fine - the DLL is probably released when the last token is returned to GdiPlusShutdown().  It's not documented, however, so that's a complete assumption, and relying on that assumption could be disastrous in the future.. To be safe, I personally chose (and still choose) to do this pair of calls ONCE for an entire application. This can be done with a singleton class wrapping the gdiplus dll (may fit nice with your wrapper class), or simply calling the startup/shutdown functions during app initialization/cleanup. Mark

          Mark Salsbery Microsoft MVP - Visual C++ :java:

          I L 2 Replies Last reply
          0
          • I indigox3

            I've got a class that wraps GDI+. In the constructor I call GdiplusStartup, and in the destructor I call GdiplusShutdown. This could result in multiple startup & shutdown calls. (And possibly several startup calls before any shutdown calls) Is it safe to make these calls multiple times?

            L Offline
            L Offline
            Lost User
            wrote on last edited by
            #5

            Thanks for the question, I did not know the answer and I was curious myself so I took the liberty of investigating. My first clue was in the MSDN It says: Each call to GdiplusStartup should be paired with a call to GdiplusShutdown. http://msdn2.microsoft.com/en-us/library/ms534076.aspx[^] So I fired up IDA Pro and began dissassembling gdiplus.dll to have a look at the op-codes. I always want to know whats really going on. Indeed, it appears each call to GdiplusStartup results in the critical section wrapped incrementing of a reference counter. Subsequently each call to GdiplusShutdown performs the opposite with the decrementing of the reference counter dword_7A20A040. Cleanup of the objects does not appear to take place until the reference count is zero. So it seems it is indeed safe to call GdiplusStartup/GdiplusShutdown in parallel between threads, and even within the same thread. As long as each GdiplusStartup is followed by a GdiplusShutdown. Best Wishes, -Randor (David Delaune)

            M I 2 Replies Last reply
            0
            • L Lost User

              Thanks for the question, I did not know the answer and I was curious myself so I took the liberty of investigating. My first clue was in the MSDN It says: Each call to GdiplusStartup should be paired with a call to GdiplusShutdown. http://msdn2.microsoft.com/en-us/library/ms534076.aspx[^] So I fired up IDA Pro and began dissassembling gdiplus.dll to have a look at the op-codes. I always want to know whats really going on. Indeed, it appears each call to GdiplusStartup results in the critical section wrapped incrementing of a reference counter. Subsequently each call to GdiplusShutdown performs the opposite with the decrementing of the reference counter dword_7A20A040. Cleanup of the objects does not appear to take place until the reference count is zero. So it seems it is indeed safe to call GdiplusStartup/GdiplusShutdown in parallel between threads, and even within the same thread. As long as each GdiplusStartup is followed by a GdiplusShutdown. Best Wishes, -Randor (David Delaune)

              M Offline
              M Offline
              Mark Salsbery
              wrote on last edited by
              #6

              Cool!  Thanks for that analysis :) Cheers, Mark

              Mark Salsbery Microsoft MVP - Visual C++ :java:

              1 Reply Last reply
              0
              • L Lost User

                Thanks for the question, I did not know the answer and I was curious myself so I took the liberty of investigating. My first clue was in the MSDN It says: Each call to GdiplusStartup should be paired with a call to GdiplusShutdown. http://msdn2.microsoft.com/en-us/library/ms534076.aspx[^] So I fired up IDA Pro and began dissassembling gdiplus.dll to have a look at the op-codes. I always want to know whats really going on. Indeed, it appears each call to GdiplusStartup results in the critical section wrapped incrementing of a reference counter. Subsequently each call to GdiplusShutdown performs the opposite with the decrementing of the reference counter dword_7A20A040. Cleanup of the objects does not appear to take place until the reference count is zero. So it seems it is indeed safe to call GdiplusStartup/GdiplusShutdown in parallel between threads, and even within the same thread. As long as each GdiplusStartup is followed by a GdiplusShutdown. Best Wishes, -Randor (David Delaune)

                I Offline
                I Offline
                indigox3
                wrote on last edited by
                #7

                Thank you so much for checking this out!

                1 Reply Last reply
                0
                • M Mark Salsbery

                  I don't know.  The docs state: "You must call GdiplusStartup before you create any GDI+ objects, and you must delete all of your GDI+ objects (or have them go out of scope) before you call GdiplusShutdown." Although there's a token associated with each startup/shutdown pair, the token (or any other context) isn't used when working with GDI+ objects.  That means there's no internal context relating created GDI+ objects with a GdiPlusStartup() call. If I had to guess, I'd say it will work fine - the DLL is probably released when the last token is returned to GdiPlusShutdown().  It's not documented, however, so that's a complete assumption, and relying on that assumption could be disastrous in the future.. To be safe, I personally chose (and still choose) to do this pair of calls ONCE for an entire application. This can be done with a singleton class wrapping the gdiplus dll (may fit nice with your wrapper class), or simply calling the startup/shutdown functions during app initialization/cleanup. Mark

                  Mark Salsbery Microsoft MVP - Visual C++ :java:

                  I Offline
                  I Offline
                  indigox3
                  wrote on last edited by
                  #8

                  I'd rather just do the initialization once like you suggest, but the code I'm working on is a module to be shared among different client apps, so I can't be sure a priori if the client is already using GDI+. Thanks for the reply,

                  1 Reply Last reply
                  0
                  • M Mark Salsbery

                    I don't know.  The docs state: "You must call GdiplusStartup before you create any GDI+ objects, and you must delete all of your GDI+ objects (or have them go out of scope) before you call GdiplusShutdown." Although there's a token associated with each startup/shutdown pair, the token (or any other context) isn't used when working with GDI+ objects.  That means there's no internal context relating created GDI+ objects with a GdiPlusStartup() call. If I had to guess, I'd say it will work fine - the DLL is probably released when the last token is returned to GdiPlusShutdown().  It's not documented, however, so that's a complete assumption, and relying on that assumption could be disastrous in the future.. To be safe, I personally chose (and still choose) to do this pair of calls ONCE for an entire application. This can be done with a singleton class wrapping the gdiplus dll (may fit nice with your wrapper class), or simply calling the startup/shutdown functions during app initialization/cleanup. Mark

                    Mark Salsbery Microsoft MVP - Visual C++ :java:

                    L Offline
                    L Offline
                    led mike
                    wrote on last edited by
                    #9

                    Mark Salsbery wrote:

                    The docs state:

                    Seems pretty clear to me :rolleyes: "Each call to GdiplusStartup should be paired....."

                    GdiplusShutdown Function

                    The GdiplusShutdown function cleans up resources used by Microsoft Windows GDI+. Each call to GdiplusStartup should be paired with a call to GdiplusShutdown.

                    1 Reply Last reply
                    0
                    • I indigox3

                      Not much relevant to my question. http://msdn2.microsoft.com/en-us/library/ms534077.aspx

                      L Offline
                      L Offline
                      led mike
                      wrote on last edited by
                      #10

                      indigox3 wrote:

                      Not much relevant to my question.

                      Seems pretty clear to me :rolleyes: "Each call to GdiplusStartup should be paired....."

                      GdiplusShutdown Function

                      The GdiplusShutdown function cleans up resources used by Microsoft Windows GDI+. Each call to GdiplusStartup should be paired with a call to GdiplusShutdown.

                      1 Reply Last reply
                      0
                      Reply
                      • Reply as topic
                      Log in to reply
                      • Oldest to Newest
                      • Newest to Oldest
                      • Most Votes


                      • Login

                      • Don't have an account? Register

                      • Login or register to search.
                      • First post
                        Last post
                      0
                      • Categories
                      • Recent
                      • Tags
                      • Popular
                      • World
                      • Users
                      • Groups