Posted By

jimfred on 03/02/10


Versions (?)

Who likes this?

1 person have marked this snippet as a favorite


C++, DLL, shared memory using pragma without touching .DEF file

 / Published in: C++

myShared is an arbitrary name. It must not collide with names .bss etc (see /SECTION in MSDN).

RWS indicates Read/Write/Shared. (See /SECTION in MSDN)

Avoid sharing process-specific info such as pointers, HANDLEs etc.

Won't work with Vista Services.

  1. #pragma data_seg(".myShared")
  2. #pragma comment(linker, "/SECTION:.myShared,RWS")
  3. int shared = 1; // goes in .myShared. Must be initialized.
  4. #pragma data_seg() // revert to default

Report this snippet  

You need to login to post a comment.