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. COM
  4. Sharing variable between instances of COM object?

Sharing variable between instances of COM object?

Scheduled Pinned Locked Moved COM
c++comsysadminhelpquestion
3 Posts 2 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.
  • M Offline
    M Offline
    Mike the Red
    wrote on last edited by
    #1

    I need to share values between two instances of a COM object. In most of the C++ COM examples I've read, an extern UINT g_DllLockCount is declared in stdafx.h and used to maintain a count of references to the Dll. DllCanUnloadNow() then uses this to determine if the Dll can be unloaded. I've tried adding an extern BSTR g_bString to the stdafx.h, and modifying DllCanUnloadNow() to return S_FALSE if g_bString isn't NULL. I've added three functions to the COM Server - one to set a string value, one to retreive the string value, and one to set the value to NULL so the Dll can unload. In my test app, I created the COM object and gave the string a value, destroyed the COM object, created another COM object, retreived the string value, then set the string to NULL so the Dll can unload. The value retreived is the initialized value of g_bString, rather than the one I set. My questions now, are: (1) Is what I'm trying to do even possible with COM ? (2) Is the method outlined above correct, and it's most likely an implementation issue, or is the method itself flawed? Any information or suggested reading ya'll can provide would be greatly appreciated. MZR

    F 1 Reply Last reply
    0
    • M Mike the Red

      I need to share values between two instances of a COM object. In most of the C++ COM examples I've read, an extern UINT g_DllLockCount is declared in stdafx.h and used to maintain a count of references to the Dll. DllCanUnloadNow() then uses this to determine if the Dll can be unloaded. I've tried adding an extern BSTR g_bString to the stdafx.h, and modifying DllCanUnloadNow() to return S_FALSE if g_bString isn't NULL. I've added three functions to the COM Server - one to set a string value, one to retreive the string value, and one to set the value to NULL so the Dll can unload. In my test app, I created the COM object and gave the string a value, destroyed the COM object, created another COM object, retreived the string value, then set the string to NULL so the Dll can unload. The value retreived is the initialized value of g_bString, rather than the one I set. My questions now, are: (1) Is what I'm trying to do even possible with COM ? (2) Is the method outlined above correct, and it's most likely an implementation issue, or is the method itself flawed? Any information or suggested reading ya'll can provide would be greatly appreciated. MZR

      F Offline
      F Offline
      frx96
      wrote on last edited by
      #2

      you can use share memory when sharing data between EXE and COM or between COM and COM: CreateFileMapping OpenFileMapping MapViewOfFile

      M 1 Reply Last reply
      0
      • F frx96

        you can use share memory when sharing data between EXE and COM or between COM and COM: CreateFileMapping OpenFileMapping MapViewOfFile

        M Offline
        M Offline
        Mike the Red
        wrote on last edited by
        #3

        Looks like I've got some serious reading to do... Thanks for pointing the way, frx96!

        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