Hi,
I am using wm_copydata to send messages to another window but sometimes I
see an extra character at the end of the message in the other process. The
message on my side before sending seems correct but sometimes an extra
character is appended on the receiving applications end. I am not sure why
this is happening ,This is my code

char* data = new char[13000];

CWnd *pOtherWnd = CWnd::FindWindow(NULL, WindowName);
LRESULT copyDataResult;
if (pOtherWnd)
{
COPYDATASTRUCT cpd;
cpd.dwData = 1;
cpd.cbData = strlen(data);
cpd.lpData = (void*)data;
copyDataResult = pOtherWnd->SendMessage(WM_COPYDATA,(WPARAM)
AfxGetApp()->m_pMainWnd->GetSafeHwnd(),(LPARAM)&cpd);
return true;
}

Any help is greatly appreciated

Thanks,
-Jimmy

Re: wm_copydata by Michael

Michael
Thu May 26 11:43:13 CDT 2005

Well, need to see the receiver code, too, but I bet it is expecting the
string to be NULL-terminated. The sender, though, isn't sending the
NULL-terminator. Set cbData to strlen(data) + 1.

--
Michael Salamone [eMVP]
Entrek Software, Inc.
www.entrek.com


"Jimmy" <Jimmy@discussions.microsoft.com> wrote in message
news:BC200D70-A4DF-42B1-AAA9-DAAB5A5A3075@microsoft.com...
> Hi,
> I am using wm_copydata to send messages to another window but sometimes
> I
> see an extra character at the end of the message in the other process. The
> message on my side before sending seems correct but sometimes an extra
> character is appended on the receiving applications end. I am not sure why
> this is happening ,This is my code
>
> char* data = new char[13000];
>
> CWnd *pOtherWnd = CWnd::FindWindow(NULL, WindowName);
> LRESULT copyDataResult;
> if (pOtherWnd)
> {
> COPYDATASTRUCT cpd;
> cpd.dwData = 1;
> cpd.cbData = strlen(data);
> cpd.lpData = (void*)data;
> copyDataResult = pOtherWnd->SendMessage(WM_COPYDATA,(WPARAM)
> AfxGetApp()->m_pMainWnd->GetSafeHwnd(),(LPARAM)&cpd);
> return true;
> }
>
> Any help is greatly appreciated
>
> Thanks,
> -Jimmy



Re: wm_copydata by Jimmy

Jimmy
Thu May 26 14:21:10 CDT 2005

This the reciever code

CString str = (LPCSTR) (pCopyDataStruct->lpData);

Thanks,
-Jimmy

"Michael J. Salamone" wrote:

> Well, need to see the receiver code, too, but I bet it is expecting the
> string to be NULL-terminated. The sender, though, isn't sending the
> NULL-terminator. Set cbData to strlen(data) + 1.
>
> --
> Michael Salamone [eMVP]
> Entrek Software, Inc.
> www.entrek.com
>
>
> "Jimmy" <Jimmy@discussions.microsoft.com> wrote in message
> news:BC200D70-A4DF-42B1-AAA9-DAAB5A5A3075@microsoft.com...
> > Hi,
> > I am using wm_copydata to send messages to another window but sometimes
> > I
> > see an extra character at the end of the message in the other process. The
> > message on my side before sending seems correct but sometimes an extra
> > character is appended on the receiving applications end. I am not sure why
> > this is happening ,This is my code
> >
> > char* data = new char[13000];
> >
> > CWnd *pOtherWnd = CWnd::FindWindow(NULL, WindowName);
> > LRESULT copyDataResult;
> > if (pOtherWnd)
> > {
> > COPYDATASTRUCT cpd;
> > cpd.dwData = 1;
> > cpd.cbData = strlen(data);
> > cpd.lpData = (void*)data;
> > copyDataResult = pOtherWnd->SendMessage(WM_COPYDATA,(WPARAM)
> > AfxGetApp()->m_pMainWnd->GetSafeHwnd(),(LPARAM)&cpd);
> > return true;
> > }
> >
> > Any help is greatly appreciated
> >
> > Thanks,
> > -Jimmy
>
>
>

Re: wm_copydata by Chris

Chris
Thu May 26 14:28:31 CDT 2005

And as Michael said, you're not passing the null terminator, so this will
fail. I'm somewhat leery of the use of char strings with CE as well, but
maybe the CString class handles that.

--
Chris Tacke
Co-founder
OpenNETCF.org
Has OpenNETCF helped you? Consider donating to support us!
http://www.opennetcf.org/donate


"Jimmy" <Jimmy@discussions.microsoft.com> wrote in message
news:0BD84CC8-6814-42B6-A127-F5BAFD3EC052@microsoft.com...
> This the reciever code
>
> CString str = (LPCSTR) (pCopyDataStruct->lpData);
>
> Thanks,
> -Jimmy
>
> "Michael J. Salamone" wrote:
>
>> Well, need to see the receiver code, too, but I bet it is expecting the
>> string to be NULL-terminated. The sender, though, isn't sending the
>> NULL-terminator. Set cbData to strlen(data) + 1.
>>
>> --
>> Michael Salamone [eMVP]
>> Entrek Software, Inc.
>> www.entrek.com
>>
>>
>> "Jimmy" <Jimmy@discussions.microsoft.com> wrote in message
>> news:BC200D70-A4DF-42B1-AAA9-DAAB5A5A3075@microsoft.com...
>> > Hi,
>> > I am using wm_copydata to send messages to another window but
>> > sometimes
>> > I
>> > see an extra character at the end of the message in the other process.
>> > The
>> > message on my side before sending seems correct but sometimes an extra
>> > character is appended on the receiving applications end. I am not sure
>> > why
>> > this is happening ,This is my code
>> >
>> > char* data = new char[13000];
>> >
>> > CWnd *pOtherWnd = CWnd::FindWindow(NULL, WindowName);
>> > LRESULT copyDataResult;
>> > if (pOtherWnd)
>> > {
>> > COPYDATASTRUCT cpd;
>> > cpd.dwData = 1;
>> > cpd.cbData = strlen(data);
>> > cpd.lpData = (void*)data;
>> > copyDataResult = pOtherWnd->SendMessage(WM_COPYDATA,(WPARAM)
>> > AfxGetApp()->m_pMainWnd->GetSafeHwnd(),(LPARAM)&cpd);
>> > return true;
>> > }
>> >
>> > Any help is greatly appreciated
>> >
>> > Thanks,
>> > -Jimmy
>>
>>
>>



Re: wm_copydata by Jimmy

Jimmy
Thu May 26 16:54:04 CDT 2005

Thanks a lot!!

"Michael J. Salamone" wrote:

> Well, need to see the receiver code, too, but I bet it is expecting the
> string to be NULL-terminated. The sender, though, isn't sending the
> NULL-terminator. Set cbData to strlen(data) + 1.
>
> --
> Michael Salamone [eMVP]
> Entrek Software, Inc.
> www.entrek.com
>
>
> "Jimmy" <Jimmy@discussions.microsoft.com> wrote in message
> news:BC200D70-A4DF-42B1-AAA9-DAAB5A5A3075@microsoft.com...
> > Hi,
> > I am using wm_copydata to send messages to another window but sometimes
> > I
> > see an extra character at the end of the message in the other process. The
> > message on my side before sending seems correct but sometimes an extra
> > character is appended on the receiving applications end. I am not sure why
> > this is happening ,This is my code
> >
> > char* data = new char[13000];
> >
> > CWnd *pOtherWnd = CWnd::FindWindow(NULL, WindowName);
> > LRESULT copyDataResult;
> > if (pOtherWnd)
> > {
> > COPYDATASTRUCT cpd;
> > cpd.dwData = 1;
> > cpd.cbData = strlen(data);
> > cpd.lpData = (void*)data;
> > copyDataResult = pOtherWnd->SendMessage(WM_COPYDATA,(WPARAM)
> > AfxGetApp()->m_pMainWnd->GetSafeHwnd(),(LPARAM)&cpd);
> > return true;
> > }
> >
> > Any help is greatly appreciated
> >
> > Thanks,
> > -Jimmy
>
>
>