Sharing a global/static variable between a process and DLL

前端 未结 8 1568
借酒劲吻你
借酒劲吻你 2020-11-27 04:16

I\'d like to share a static/global variable only between a process and a dll that is invoked by the process. The exe and dll are in the same memory address space. I don\'t w

相关标签:
8条回答
  • 2020-11-27 04:59

    If I understand your question correctly, you are statically linking a.cpp into foo.exe and bar.dll, so you get 2 instances of x.

    If you created a third dll (say a.dll), and you dynamically link foo.exe and bar.dll to a.dll, you will get the behaviour you desire:

    1. foo.exe loads a.dll and creates x.
    2. bar.dll gets loaded and sees that a.dll is loaded and doesn't load it again, they share x.
    3. Another process loads a.dll, it gets its own x.
    0 讨论(0)
  • 2020-11-27 05:03

    Thanks for providing various solution on this. i have looked at these option and decided to implement the cross module singleton using the Shared Memory and it worked well for me as well. i have used Qt QSharedMemory to achieve my task but the prototype i wrote using the Win32 CreateFileMapping & etc.

    0 讨论(0)
提交回复
热议问题