August 2nd, 1999, 05:11 PM
How to share a memory variable between the two different processes(Applications)?
|
Click to See Complete Forum and Search --> : Sharing memory variables August 2nd, 1999, 05:11 PM How to share a memory variable between the two different processes(Applications)? August 2nd, 1999, 06:16 PM You can use memory mapped files (OpenFileMapping() to open a memory mapped file). Otherwise you cannot share memory variables between processes. Neerka August 3rd, 1999, 08:53 AM 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 Wayne Fuller August 3rd, 1999, 08:59 AM 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 August 3rd, 1999, 09:48 AM hai wayne fuller, thanks for the reply , yah i need ,and if you can . Thanks sree. Wayne Fuller August 3rd, 1999, 10:16 AM 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 Gomez Addams August 3rd, 1999, 11:48 AM 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/wicked/wicked1198top.htm August 4th, 1999, 08:33 AM 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. August 4th, 1999, 04:50 PM Thanks for help gomez addams, it solved my problem. codeguru.com
Copyright Internet.com Inc., All Rights Reserved. |