 |
|
 |
I have created to applications for sending string between 2 but in the receiver application only the base address is received
Sender Application
CWnd *pOtherWnd = CWnd::FindWindow(NULL, L"Receiver");
LRESULT copyDataResult;
if (pOtherWnd !=NULL)
{
COPYDATASTRUCT cpd;
CString strDataToSend = _T("Adeel");
cpd.dwData = 0; cpd.cbData = strDataToSend.GetLength() + 1;
cpd.lpData = (void*)strDataToSend.GetBuffer(strDataToSend.GetLength()); copyDataResult = pOtherWnd->SendMessage(WM_COPYDATA, (WPARAM)AfxGetApp()->m_pMainWnd->GetSafeHwnd(), (LPARAM)&cpd);
strDataToSend.ReleaseBuffer();
}
Receiver Application
<code>
BOOL CReceiverDlg::OnCopyData(CWnd* pWnd, COPYDATASTRUCT* pCopyDataStruct)
{
LPCSTR m_rxText = (LPCSTR)(pCopyDataStruct->lpData);
CString strTest = _T("");
strTest = (LPCSTR)(pCopyDataStruct->lpData);
return CDialog::OnCopyData(pWnd, pCopyDataStruct);
}
</code>
Only A is getting stored inside m_rxText and strTest
Maverick
|
|
|
|
 |
|
 |
Try this :
void CDlgTestDlg::OnBnClickedButton1()
{
static int counter=0;
CWnd *pOtherWnd = CWnd::FindWindow(NULL, L"Receiver");
LRESULT copyDataResult;
if (pOtherWnd !=NULL)
{
COPYDATASTRUCT cpd;
char strDataToSend[5];
sprintf(strDataToSend,"%d",counter++);
cpd.dwData = 0;
cpd.cbData = sizeof(strDataToSend);
cpd.lpData = (void*)&strDataToSend; // a pointer to the buffer containing
copyDataResult = pOtherWnd->SendMessage(WM_COPYDATA, (WPARAM)AfxGetApp()->m_pMainWnd->GetSafeHwnd(),(LPARAM)&cpd);
}
|
|
|
|
 |
|
 |
cpd.cbData = txt.GetLength()+1;
cpd.lpData = (void*)txt.GetBuffer(txt.GetLength()+1);
|
|
|
|
 |
|
 |
1. Can you give a quick example of receiving a structure on the receiving end of the WM_COPYDATA message?
2. How come when I put the data I'm sending in a message box it shows garbage at the end of the text? Do I need to truncate the data based on the size of the data being sent?
Thanks
Tom Wright
tawright915@yahoo.com
|
|
|
|
 |
|
 |
if an app is minimized/hide or sits in system tray, can we still find a handle to that app? is FindWindow works if so?
|
|
|
|
 |
|
 |
Yes,you still find the handle to window if the app is minimized or hidden or sit in system tray you can test this.
i myself i trying to write a article over findwindow api,but time is not permiting me to write
-----------------------------
"I Think It Will Help"
-----------------------------
Alok Gupta
visit me at http://www.thisisalok.tk
|
|
|
|
 |
|
 |
nice one. i'm rewriting this whole thing myself. let's see who gets it done first?
cheers!
|
|
|
|
 |
|
 |
Then Best of Luck Buddy,i Will Pray to god That the Best One Win (i think thats You!!)
-----------------------------
"I Think this Will Help"
-----------------------------
Alok Gupta
visit me at http://www.thisisalok.tk
|
|
|
|
 |
|
 |
Hi eddie
i m new kid on the VC++ block. I am presently wrking on a virtual classroom application. I have made use of Windows Media Encoder in order to broadcast audio video information.
In this application i need to share applications and sync with all the connected users (a concept of VNC).
Can u plzz guide me in how can i achieve desktop sharing
as well as is there any better option for Video Conferencing like the H323 protocol used by netmeeting.
Thank you in advance
regards
ashutosh
|
|
|
|
 |
|
 |
Very good suggestion!!! I have one question though: Can this approach be used as the basis for IPC communication in a multi client environment. That means 1 server where all executables live and execute and many clients accessing these executables at the same time.
Spiros Prantalos
|
|
|
|
 |
|
 |
Yes. The only problem would be identifying the senders of the data as there might be multiple sessions going on at the same time. I would add the sender ID in the data packet so that the receiver can identify the sender.
Other than that, nothing speical to do.
Eddy
|
|
|
|
 |
|
 |
What if I want to have a bidirectional transfer of data, that is from clientX to clientY and after some process there to transfer data back to clientX?
Spiros Prantalos
|
|
|
|
 |
|
 |
Hi,
I would suggest TCP socket connection. It's available at every system that has a networkcard or a modem (for internet access) installed and allows you to run the client and server on divverent computers.
For more information read some network specific articles on codeproject.
Ciao Matthias Mann
|
|
|
|
 |
|
 |
Spiros Hi,
my name is Zac Prantalos, where are u coming from?
|
|
|
|
 |
|
 |
Same country you are coming from. Hellas
Spiros Prantalos
Miami the place to be!!
|
|
|
|
 |
|
 |
Hi,
the WM_COPYDATA message was exactly what I needed after struggling how to send data to another instance of my programm. However, there is a small bug in your code or at least something which can lead to an unwanted sideeffect:
cpd.cbData = strDataToSend.GetLength();
If you set the size of the data to be copied exactly to the number of characters the last \0 character won't be copied! Usually you cannot assume that all memory is initialized with 0s so the line in your messagehandler:
CString strRecievedText = (LPCSTR) (pCopyDataStruct->lpData);
can result in garbage appending your string. There are 2 solutions to this problem: either check the length of the data to be copied in your message handler and DON'T copy the memory directly into a CString or modify the first line into:
cpd.cbData = strDataToSend.GetLength() + 1;
Ciao,
Andreas
|
|
|
|
 |
|
 |
I tried on my App.
My window title has a tail of Title - [doc1].
This make the FindWindow useless.
JW
|
|
|
|
 |
|
 |
The 'FindWindow' has nothing to do with WM_COPDATA. It is just the way the sample was setup, there is a number of other ways to find the other app. One I use most is the private message with the window handle in the long data.
Eddy
|
|
|
|
 |
|
 |
You could try enumerating processes (if you know the name of the executable) and then getting the HWND through the process info.
------- signature starts
"...the staggering layers of obscenity in your statement make it a work of art on so many levels." - Jason Jystad, 10/26/2001
Please review the Legal Disclaimer in my bio.
------- signature ends
|
|
|
|
 |
|
 |
This is a strange thing that is occurring. We are reading data from a file and then using WM_COPYDATA withing SendMessage to pass the information read to another application. We read the first set of data just fine and send it over, but then the second read fails. GetErrorStatus return 288 as the error. If we comment out the SendMessage call all reads work just fine. What could be causing this? I am a hopelessly lost UNIX ANSI C programmer and any advice would be of benefit.
|
|
|
|
 |
|
 |
I am using your example as framework for a logging application that I am writing. (Thanks for the great idea!!) Based on what I have read about the SendMessage() API call, there is a potential blocking problem. Use of PostMessage would probably result in data corruption as the temporary data may change before the posted message is read. If the receiving process is broken or busy and it cannot respond quickly to the sent message, is there someway to prevent a deadlock?
TIA
David
|
|
|
|
 |
|
 |
how about SendMessageTimeout(...)?
|
|
|
|
 |
|
 |
Hi
check out this link, it's a much cleaner way to do this using own registered messages and not only FindWindow().
http://msdn.microsoft.com/msdnmag/issues/0900/c/c0900.asp
|
|
|
|
 |
|
 |
I'm sure that will also work, but why would it be 'much cleaner' ?
BTW, did you find the other problem ? (the one where you got garbage in the data).
Eddy
|
|
|
|
 |
|
 |
Hi Eddy
the "much cleaner" is because it doesn't use only FindWindow() which sometimes can hang up in so-called "race conditions". Please read the excellent article "Avoiding multiple instances" by J.M. Newcomer:
http://codeproject.com/cpp/avoidmultinstance.asp
To my problem: no, unfortunately not yet. I got pointed to the fact it could be cause my 2nd instance can't access the buffer where the arguments are stored in by the 1st instance, so I used an explicit GlobalAlloc() and passed over the HGLOBAL to do an GlobalLock() in the 2nd instance and get the data that way: same effect. So it must be something else I'm doing wrong here.
Cheers
Yann
|
|
|
|
 |