shared memory in DLLs?

This is a discussion on shared memory in DLLs? within the Windows Programming forums, part of the Platform Specific Boards category; I'm trying to share a variable across multiple processes/threads, and make it so that if one process updates the value, ...

  1. #1
    Registered User
    Join Date
    Aug 2003
    Posts
    288

    shared memory in DLLs?

    I'm trying to share a variable across multiple processes/threads, and make it so that if one process updates the value, all the other processes 'get' the new value.

    I read that I could/should use mutex's/semaphores/interlocked* funcs/critical sections/events/file mappings, but I wasnt sure which or why. Heres the code Im using atm, is this a safe method of doing it?

    Thanks in advance for any help.

    Code:
    #include <windows.h>
    #include <tchar.h>
    
    #pragma data_seg("SHARED")
    
    int nSharedCount;
    
    #pragma data_seg()
    
    #pragma comment(linker, "/section:SHARED,RWS")
    
    BOOL APIENTRY DllMain(HMODULE hModule, DWORD dwReason, LPVOID lpReserved)
    {
    	switch (dwReason) 
    	{ 
    		case DLL_PROCESS_ATTACH:
    		{
    			
    		}
    		break; 
    
    		case DLL_PROCESS_DETACH:
    		{
    
    		}
    		break; 
    	}
    }
    
    void GetCount()
    {
    	return nSharedCount;
    }
    
    void SetCount(int nCount)
    {
    	nSharedCount = nCount;
    }

  2. #2
    erstwhile
    Join Date
    Jan 2002
    Posts
    2,227
    CProgramming FAQ
    Caution: this person may be a carrier of the misinformation virus.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Share segment
    By ch4 in forum C Programming
    Replies: 7
    Last Post: 12-30-2008, 01:19 AM
  2. Shared memory woes
    By joshdick in forum C Programming
    Replies: 4
    Last Post: 07-28-2005, 08:59 AM
  3. Pointer's
    By xlordt in forum C Programming
    Replies: 13
    Last Post: 10-14-2003, 02:15 PM
  4. Managing shared memory lookups
    By clancyPC in forum Linux Programming
    Replies: 0
    Last Post: 10-08-2003, 04:44 AM
  5. Shared memory in Linux: B-TREE of structures
    By zahid in forum Linux Programming
    Replies: 3
    Last Post: 01-26-2002, 10:15 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21