468,513 Members | 1,873 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,513 developers. It's quick & easy.

Limitations of #pragma section shared, rws

Semprini
Hiya,

I'm programming a dll in VC6 which is uses windows hooks (WH_GETMESSAGE). So I have a HOOKPROC which is called whenever messages are sent the the monitored hwnd

I have a shared data segment like so:

Expand|Select|Wrap|Line Numbers
  1. #pragma data_seg("SHARED")
  2. ...variables in here
  3. #pragma data_seg()
  4. #pragma comment(linker, "/section:SHARED,RWS")
  5.  
If I put a variable of a class, struct or std::vector (probably anything but simple types) into the shared segment when the HOOKPROC is called the variable is null

I must be missing something about how the shared segment works. Anybody have any ideas? I'd love to be able to have a std::list of a structure containing info about what messages the HOOKPROC should reply to and how to reply.

Looks like I'll have to use arrays of hwnd's and others for the moment...

Cheers,

Semprini
Aug 15 '06 #1
2 9632
After further investigation it seems that all my shared variables need to be initialized:

this doesn't work:

Expand|Select|Wrap|Line Numbers
  1. #pragma data_seg("aSHARED")
  2. static DWORD g_dwProcessIDs[MAX_MSGHOOKS];
  3. #pragma data_seg()
  4. #pragma comment(linker, "/section:aSHARED,RWS")
  5.  
but this does:

Expand|Select|Wrap|Line Numbers
  1. #pragma data_seg("aSHARED")
  2. static DWORD g_dwProcessIDs[MAX_MSGHOOKS] = {0};
  3. #pragma data_seg()
  4. #pragma comment(linker, "/section:aSHARED,RWS")
  5.  
Why would the variable go out of scope if not initialized??
Aug 15 '06 #2
Cronus
1
After further investigation it seems that all my shared variables need to be initialized:

this doesn't work:

Expand|Select|Wrap|Line Numbers
  1. #pragma data_seg("aSHARED")
  2. static DWORD g_dwProcessIDs[MAX_MSGHOOKS];
  3. #pragma data_seg()
  4. #pragma comment(linker, "/section:aSHARED,RWS")
  5.  
but this does:

Expand|Select|Wrap|Line Numbers
  1. #pragma data_seg("aSHARED")
  2. static DWORD g_dwProcessIDs[MAX_MSGHOOKS] = {0};
  3. #pragma data_seg()
  4. #pragma comment(linker, "/section:aSHARED,RWS")
  5.  
Why would the variable go out of scope if not initialized??
data_seg is for initialized data. You can also specify sections for const variables (const_seg), uninitialized data (bss_seg), and functions (code_seg).
Mar 22 '07 #3

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

6 posts views Thread by Shri | last post: by
4 posts views Thread by Troy | last post: by
1 post views Thread by Gustavo L. Fabro | last post: by
11 posts views Thread by ramu | last post: by
15 posts views Thread by muttaa | last post: by
3 posts views Thread by Oops-c++ | last post: by
26 posts views Thread by Rick | last post: by
2 posts views Thread by aleemakhtar1 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.