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
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. hdc in shared mem

hdc in shared mem

Scheduled Pinned Locked Moved C / C++ / MFC
performancequestion
8 Posts 3 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.
  • F Offline
    F Offline
    Force Code
    wrote on last edited by
    #1

    Is there any way to create a memory device context that is valid between processes? If you do a HDC hdc = CreateCompatibleDC(...) its returning a pointer that's valid only for the current process address space. However, considering that DLL's can designate blocks of memory that are shared between processes, it seems you could have a mem DC shareable between processes as well.

    M 1 Reply Last reply
    0
    • F Force Code

      Is there any way to create a memory device context that is valid between processes? If you do a HDC hdc = CreateCompatibleDC(...) its returning a pointer that's valid only for the current process address space. However, considering that DLL's can designate blocks of memory that are shared between processes, it seems you could have a mem DC shareable between processes as well.

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

      An HDC is only valid within the context of the process that created it. You can share the handle in a shared data segment but that won't make it valid to another process. What part(s) of the device context are you looking to share between processes? Mark

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

      F 1 Reply Last reply
      0
      • M Mark Salsbery

        An HDC is only valid within the context of the process that created it. You can share the handle in a shared data segment but that won't make it valid to another process. What part(s) of the device context are you looking to share between processes? Mark

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

        F Offline
        F Offline
        Force Code
        wrote on last edited by
        #3

        Mark Salsbery wrote:

        An HDC is only valid within the context of the process that created it. You can share the handle in a shared data segment but that won't make it valid to another process. What part(s) of the device context are you looking to share between processes?

        Just an HBITMAP, not fonts, or pens, etc. If one process does a hdc = CreateCompatibleDC(...) and SelectObject(hdc,hbmp), I want any other process to be able to BitBlt to/from it. This hdc is part of a C++ object I have defined in a shared memory segment of a DLL: G g_list __attribute__((section ("shared"), shared)); So, every process that accesses that DLL is accessing the exact same g_list and g_list members. The class doesn't contain pointers, with the exception of this hdc which I didn't realize was a local pointer.

        W M 2 Replies Last reply
        0
        • F Force Code

          Mark Salsbery wrote:

          An HDC is only valid within the context of the process that created it. You can share the handle in a shared data segment but that won't make it valid to another process. What part(s) of the device context are you looking to share between processes?

          Just an HBITMAP, not fonts, or pens, etc. If one process does a hdc = CreateCompatibleDC(...) and SelectObject(hdc,hbmp), I want any other process to be able to BitBlt to/from it. This hdc is part of a C++ object I have defined in a shared memory segment of a DLL: G g_list __attribute__((section ("shared"), shared)); So, every process that accesses that DLL is accessing the exact same g_list and g_list members. The class doesn't contain pointers, with the exception of this hdc which I didn't realize was a local pointer.

          W Offline
          W Offline
          Waldermort
          wrote on last edited by
          #4

          Force Code wrote:

          Just an HBITMAP

          Sharing pointers between processes is a no-no, you need to share the data. In this case that data is called a "dib section".

          Waldermort

          1 Reply Last reply
          0
          • F Force Code

            Mark Salsbery wrote:

            An HDC is only valid within the context of the process that created it. You can share the handle in a shared data segment but that won't make it valid to another process. What part(s) of the device context are you looking to share between processes?

            Just an HBITMAP, not fonts, or pens, etc. If one process does a hdc = CreateCompatibleDC(...) and SelectObject(hdc,hbmp), I want any other process to be able to BitBlt to/from it. This hdc is part of a C++ object I have defined in a shared memory segment of a DLL: G g_list __attribute__((section ("shared"), shared)); So, every process that accesses that DLL is accessing the exact same g_list and g_list members. The class doesn't contain pointers, with the exception of this hdc which I didn't realize was a local pointer.

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

            I was going to suggest the same thing as WalderMort - A DIB section through a named file mapping (in-memory). All the info you need to create the DIBSection and a memory DC in the second process can be shared. See CreateDIBSection()[^]. Mark

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

            F 1 Reply Last reply
            0
            • M Mark Salsbery

              I was going to suggest the same thing as WalderMort - A DIB section through a named file mapping (in-memory). All the info you need to create the DIBSection and a memory DC in the second process can be shared. See CreateDIBSection()[^]. Mark

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

              F Offline
              F Offline
              Force Code
              wrote on last edited by
              #6

              Mark Salsbery wrote:

              I was going to suggest the same thing as WalderMort - A DIB section through a named file mapping (in-memory). All the info you need to create the DIBSection and a memory DC in the second process can be shared. See CreateDIBSection()[^].

              We must be looking at documentation near simultaneously, somehow. I saw the file mapping thing but ruled it out as too byzantine (for my tastes). What I did instead was to make hdc static in the class - which results in each process having its own copy - strangely. Since the class is in shared memory, making it nonstatic means every process has the same copy - static results in the opposite in this case. Then I have another new static member local_cnt. if local_cnt != (nonstatic)cnt then the static hdc is deleted and recreated (thus synchronizing with changes elsewhere.

              W 1 Reply Last reply
              0
              • F Force Code

                Mark Salsbery wrote:

                I was going to suggest the same thing as WalderMort - A DIB section through a named file mapping (in-memory). All the info you need to create the DIBSection and a memory DC in the second process can be shared. See CreateDIBSection()[^].

                We must be looking at documentation near simultaneously, somehow. I saw the file mapping thing but ruled it out as too byzantine (for my tastes). What I did instead was to make hdc static in the class - which results in each process having its own copy - strangely. Since the class is in shared memory, making it nonstatic means every process has the same copy - static results in the opposite in this case. Then I have another new static member local_cnt. if local_cnt != (nonstatic)cnt then the static hdc is deleted and recreated (thus synchronizing with changes elsewhere.

                W Offline
                W Offline
                Waldermort
                wrote on last edited by
                #7

                Force Code wrote:

                What I did instead was to make hdc static in the class

                And in a few weeks you will be asking why your code is crashing unexpectedly.

                Waldermort

                M 1 Reply Last reply
                0
                • W Waldermort

                  Force Code wrote:

                  What I did instead was to make hdc static in the class

                  And in a few weeks you will be asking why your code is crashing unexpectedly.

                  Waldermort

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

                  ...or days :)

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

                  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