Sharing a global/static variable between a process and DLL

前端 未结 8 1598
借酒劲吻你
借酒劲吻你 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:56

    If foo.exe always loads bar.dll then you can implement the variable in bar.dll and export it. For example, some file b.cpp compiled only into bar.dll, not into foo.exe:

    __declspec(dllexport) int x;
    

    Then import it in a source file c.cpp compiled into foo.exe:

    __declspec(dllimport) int x;
    

    However, if sometimes foo.exe doesn't load bar.dll then this won't work. Also, I'm writing this from memory and so there might be some syntactical errors, but hopefully it's enough to point you in the right direction.

    I can't answer why it's different Linux.

提交回复
热议问题