sharing a pointer between the applications
-
I have created two exes(MFC).I am posting a pointer to the structure thro' PostThreadMessage from one exe (struct message { int messageid; CString messagedescription; }; the members are initialized ) The other exe should receive the pointer posted by the thread from other exe & it should display the member values.But, in my case the structure is getting posted successfully !But, I am getting some junk values in the receiving exe. How can I get the desired values, then ? Y.Yamini Devi
-
I have created two exes(MFC).I am posting a pointer to the structure thro' PostThreadMessage from one exe (struct message { int messageid; CString messagedescription; }; the members are initialized ) The other exe should receive the pointer posted by the thread from other exe & it should display the member values.But, in my case the structure is getting posted successfully !But, I am getting some junk values in the receiving exe. How can I get the desired values, then ? Y.Yamini Devi
You can't pass data between different programs like that. Each program has its own address space, and pointers in one app don't make sense in another app. Either switch to WM_COPYDATA or use memory-mapped files. --Mike-- http://home.inreach.com/mdunn/ This must be Thursday. I never could get the hang of Thursdays...
-
You can't pass data between different programs like that. Each program has its own address space, and pointers in one app don't make sense in another app. Either switch to WM_COPYDATA or use memory-mapped files. --Mike-- http://home.inreach.com/mdunn/ This must be Thursday. I never could get the hang of Thursdays...
There is more way to share data between 2 or more apps. Write a simple dll and set the variable you want to share as followed: #pragma data_seg("shared") int x=0; #pragma data_seg() #pragma comment(linker,"/SECTION:shared,RWS") if you add this to a dll the variable x will be readable from all apps using this dll. if more than one process will write to x you should not forget synchronisation. BEWARE: Shared data must be init !!! This works not with dynamic variables ! Hope that helps - Mario P.S.: Sharing pointers via PostMessage has only worked under win 3.x ! ----------------------- www.klangwerker.de mario@klangwerker.de -----------------------
-
I have created two exes(MFC).I am posting a pointer to the structure thro' PostThreadMessage from one exe (struct message { int messageid; CString messagedescription; }; the members are initialized ) The other exe should receive the pointer posted by the thread from other exe & it should display the member values.But, in my case the structure is getting posted successfully !But, I am getting some junk values in the receiving exe. How can I get the desired values, then ? Y.Yamini Devi
You cannot pass pointers from one process to another. Each process has its own address space, so a pointer in process A points to process A's address space. Process B cannot access any data in process A. The simpliest way to resolve this is to write the data to a file that can be read by process B. Another way may be for process A to put the data into the clipboard and process B to extract it. There are other ways but much more complicated and involves advanced COM+ programming.;)