CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 9 of 9
  1. #1
    Guest

    Sharing memory variables

    How to share a memory variable between the two different processes(Applications)?


  2. #2
    Guest

    Re: Sharing memory variables

    You can use memory mapped files (OpenFileMapping() to open a memory mapped file). Otherwise you cannot share memory variables between processes.

    Neerka


  3. #3
    Guest

    Re: Sharing memory variables

    hello neerka,
    thanks for the reply, apart from the given solution is there any method to share the variables between the two process, means without opening and closing the file in two processes, just i want to share only two or three variables information between the two processes(DLL'S).


    Thanks
    Sree


  4. #4
    Join Date
    May 1999
    Location
    Texas, USA
    Posts
    568

    Re: Sharing memory variables

    There are one of two ways that I know about to do that sort of thing.

    You can use the Clipboard to pass information or what I would do is send a message to the other Application called WM_COPYDATA. There is a structure you pass and inside that structure you can pass anything you want. On the recieving end, if using MFC, just override OnCopyData, a CWnd member. If you need any more help on this let me know.

    Wayne


  5. #5
    Guest

    Re: Sharing memory variables

    hai wayne fuller,
    thanks for the reply , yah i need ,and if you can .

    Thanks
    sree.


  6. #6
    Join Date
    May 1999
    Location
    Texas, USA
    Posts
    568

    Re: Sharing memory variables

    This will take a couple of steps. First find the window, with FindWindow() to get its HWND. Then setup the structure to fit your needs. Then Send the message.
    // There are many ways to find a window. If you are using a MDI application
    // then normally the title might be something like "MyApp - Filename"
    // The problem here is that the Filename will change depending on the focused window
    // So my suggestion would be to call EnumWindows and in the callback function
    // try to find the title that has "MyApp". If you do not know how to do this
    // let me know and I can send that info. Here I will just assume you
    // can find the window.
    HWND hWnd = FindWindow(NULL, _T("Special Caption in Window"));

    if ( hWnd )
    {
    COPYDATASTRUCT cds;

    cds.dwData = some unique identifer, or nothing;
    cds.cbData = SIZEOF DATA;
    cds.lpData = Pointer to data, can be anything, but of course the other application has to know what it is;

    return ::SendMessage(hWnd, WM_COPYDATA, (WPARAM) AfxGetMainWnd()->GetSafeHwnd(), (LPARAM) &cds);

    }

    return FALSE;


    // In the other application
    BOOL CMainFrame::OnCopyData(CWnd* pWnd, COPYDATASTRUCT* pCopyDataStruct)
    {
    if ( pCopyDataStruct->dwData == some unique identifer )
    {
    // Do whatever you want with the data

    return TRUE;
    }

    return CMDIFrameWnd::OnCopyData(pWnd, pCopyDataStruct);
    }





    Wayne


  7. #7
    Join Date
    May 1999
    Location
    Oregon, USA
    Posts
    302

    Re: Sharing memory variables

    This link is to an article that demonstrates WM_COPYDATA :
    http://www.codeguru.com/win32/ipcdemo.shtml

    This link is to an MSJ article on shared memory. It has sample code.
    http://www.microsoft.com/MSJ/1198/wi...ked1198top.htm


  8. #8
    Guest

    Re: Sharing memory variables

    hai wayne,
    It is not a window based application , its an api i want to share the variables information between DLL and and excutable(just like a service it will run), which doesn't have windows.

    Thanks
    sree.



  9. #9
    Guest

    Re: Sharing memory variables

    Thanks for help gomez addams, it solved my problem.


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured