Shared memory between Apps

This is a discussion on Shared memory between Apps within the Windows Programming forums, part of the Platform Specific Boards category; Im working on a project that has two parts to it that need to communicate. One of the parts is ...

  1. #1
    Codebot
    Join Date
    Jun 2004
    Location
    Toronto
    Posts
    195

    Shared memory between Apps

    Im working on a project that has two parts to it that need to communicate. One of the parts is a service that runs in the background that "dispatches" messages and one or more apps that "recieve" the messages. Im wondering how one can set up a shared memory space for all these programs to access. the information being passed back and forth is too big to stuff into a custom windows message.

    can someone provice any insight on this? any links or tutorials would be greatly appreciated

    EDIT: I believe, froma previous post, this type of system is called custom marshalling.
    Last edited by Mastadex; 05-09-2006 at 11:34 AM.

  2. #2
    Yes, my avatar is stolen anonytmouse's Avatar
    Join Date
    Dec 2002
    Posts
    2,544
    You can use memory mapping.

  3. #3
    Codebot
    Join Date
    Jun 2004
    Location
    Toronto
    Posts
    195
    Thanks alot. This is exactly what i need.

    The problem is that memory mapped files are not dynamically resizable, but i can always create new "pages" or even new mapped files to store this data. this is easy stuff.

    My question now is: will continuous shared memory calls slow down the system or fragment the PAGEFILE.SYS file? Is this the most efficient way of moving lots of continuous data between processes??
    Last edited by Mastadex; 05-10-2006 at 08:08 AM.
    Founder and avid member of the Internationsl Typo Associateion

  4. #4
    Yes, my avatar is stolen anonytmouse's Avatar
    Join Date
    Dec 2002
    Posts
    2,544
    No, if you need to stream data between processes, you should use a pipe (see example 2, you can use BugMeNot to get a password). Communication between processes is known as interprocess communications.

  5. #5
    Codebot
    Join Date
    Jun 2004
    Location
    Toronto
    Posts
    195
    Alright ill change my code to use pipes now. Since im going to have many processes communicating with one main process (a service), is it possible to have many processes connected to one pipe????
    Founder and avid member of the Internationsl Typo Associateion

  6. #6
    Crazy Fool Perspective's Avatar
    Join Date
    Jan 2003
    Location
    Canada
    Posts
    2,640
    You'll need a seperate pipe for each connecting process. You should google for Beej's Guide, it will show you how to set up a simple multi-client server.

  7. #7
    Codebot
    Join Date
    Jun 2004
    Location
    Toronto
    Posts
    195
    Hmm, I opted out for WM_COPYDATA instead. The problem is now, how does one communicate with a service if services dont have a WndProc. Does this mean that the only optional route is to use pipes instead?

    EDIT: Apperently u can register a window using the bare bones. nothing but the WndProc filled into WinClassEx struct.

    Code:
    // Register class
    WinClass.cbSize			= sizeof(WNDCLASSEX); 
    WinClass.style			= NULL;//CS_OWNDC | CS_HREDRAW | CS_VREDRAW;
    WinClass.lpfnWndProc	= (WNDPROC) WndProc;
    WinClass.cbClsExtra		= 0;
    WinClass.cbWndExtra		= 0;
    WinClass.hInstance		= NULL;//hInstance;
    WinClass.hIcon			= NULL;//LoadIcon(hInstance, (LPCTSTR) "APP_ICON");
    WinClass.hCursor		= NULL;//LoadCursor(NULL, IDC_ARROW);
    WinClass.hbrBackground	= NULL;
    WinClass.lpszMenuName	= 0;
    WinClass.lpszClassName	= "bar";
    WinClass.hIconSm		= NULL;//LoadIcon(hInstance, (LPCTSTR) "APP_ICON");
    
    // Register the window
    RegisterClassEx(&WinClass);
    HWND me = CreateWindowEx(WS_EX_APPWINDOW, "bar", "bar", WS_POPUP | WS_CLIPSIBLINGS | WS_CLIPCHILDREN, 0, 0, 0, 0, NULL, NULL, NULL, NULL);

    I have all the essential stuff commented out that would make a window usable. The fact that its 0 by 0 pixels big and doesnt even have a pointer to the instance of itself.

    So if i put this in my service code, It should register the class and ill be able to send the messages into the WndProc of the service????
    Last edited by Mastadex; 05-11-2006 at 03:35 PM.
    Founder and avid member of the Internationsl Typo Associateion

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Shared Memory semaphores?
    By Ironic in forum C Programming
    Replies: 0
    Last Post: 10-31-2008, 07:13 PM
  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