Sharing a global/static variable between a process and DLL

前端 未结 8 1603
借酒劲吻你
借酒劲吻你 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.

提交回复
热议问题