WM_COPYDATA Problems (urgent) ... 
Author Message
 WM_COPYDATA Problems (urgent) ...

Hello friends, I'm having problems during run time using WM_COPYDATA
message.
The Issue is this:

I have an OCX, that have the code to send, and receive this WM_COPYDATA
message, and usually this OCX is instancied in 5 programs in real time. Well
when I'm debuging from one instance to herself, OK works right, but from one
instance to another I lose my data!!!!!!!
this is the code to send the message:
////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////
long CAlcUraCtrl::MandaMensagemA(long hWnd, long pCanal, BSTR pMensagem){
COPYDATASTRUCT cds;
 MYREC   mr;
 //
 mr.chn = pCanal;
 mr.msg = pMensagem;
 //
 cds.dwData = MYID;
 cds.cbData = sizeof(mr);
 cds.lpData = &mr;
 //
 ::SendMessage((HWND)hWnd,WM_COPYDATA,(WPARAM)pCanal,(LPARAM)&cds);

Quote:
}

////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////

where MYREC is this:
////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////
typedef struct tagMYREC{
 long chn;
 BSTR msg;

Quote:
} MYREC;

////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////

And the receiver code is this:
////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////
LRESULT JanelaAuxiliarEventos::OnMsgUraA(WPARAM wParam, LPARAM lParam){
 PCOPYDATASTRUCT pcds;
 //
 pcds = (PCOPYDATASTRUCT)lParam;
 //
 if (pcds->dwData == MYID){
  ctl->FireMensagem((long)((MYREC *)(pcds->lpData))->chn,(LPCTSTR)((MYREC
*)(pcds->lpData))->msg);
 }
 //
 return TRUE;

Quote:
}

////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////
like: ON_MESSAGE(WM_COPYDATA, OnMsgUraA)
////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////

on VB I use this way:

MyControl.MandaMensagemA(ControlerhWnd, 2, "Test using interprocess
Comunication ...")

but (when is a diferent instance I receive this on VB:


To get the hWnd of instance I create an assistant window.

Any Ideas ?????

How Can I correct this ???

Very thanks,

Danilo ...



Sat, 26 Feb 2005 04:45:14 GMT  
 WM_COPYDATA Problems (urgent) ...
WM_COPYDATA in your case successfully transfers the 32-bit value of BSTR
pointer to the other process, but of course this pointer is meaningless
there. If you want to transfer the string with WM_COPYDATA, you need to
serialize all the fields into one buffer, and set up this buffer in
COPYDATASTRUCT.

In other words, the data in COPYDATASTRUCT should not itself contain any
pointers - WM_COPYDATA does not know they are pointers and doesn't
trasfer any pointed-to memory.

Why don't you use COM mechanisms? Your components could, for example,
register themselves in the ROT and thus discover each other. COM
transparently marshals BSTRs between processes practically without any
effort on your part.
--
With best wishes,
    Igor Tandetnik

"For every complex problem, there is a solution that is simple, neat,
and wrong." H.L. Mencken



Quote:
> Hello friends, I'm having problems during run time using WM_COPYDATA
> message.
> The Issue is this:

> I have an OCX, that have the code to send, and receive this
WM_COPYDATA
> message, and usually this OCX is instancied in 5 programs in real
time. Well
> when I'm debuging from one instance to herself, OK works right, but
from one
> instance to another I lose my data!!!!!!!
> this is the code to send the message:

////////////////////////////////////////////////////////////////////////
////
Quote:
> //////////////////////////////////////////////////////////////////
> long CAlcUraCtrl::MandaMensagemA(long hWnd, long pCanal, BSTR
pMensagem){
> COPYDATASTRUCT cds;
>  MYREC   mr;
>  //
>  mr.chn = pCanal;
>  mr.msg = pMensagem;
>  //
>  cds.dwData = MYID;
>  cds.cbData = sizeof(mr);
>  cds.lpData = &mr;
>  //
>  ::SendMessage((HWND)hWnd,WM_COPYDATA,(WPARAM)pCanal,(LPARAM)&cds);
> }

////////////////////////////////////////////////////////////////////////
////
Quote:
> ///////////////////////////////////////////////////////////////////

> where MYREC is this:

////////////////////////////////////////////////////////////////////////
////
Quote:
> ///////////////////////////////////////////////////////////////////
> typedef struct tagMYREC{
>  long chn;
>  BSTR msg;
> } MYREC;

////////////////////////////////////////////////////////////////////////
////
Quote:
> //////////////////////////////////////////////////////////////////

> And the receiver code is this:

////////////////////////////////////////////////////////////////////////
////
Quote:
> //////////////////////////////////////////////////////////////////
> LRESULT JanelaAuxiliarEventos::OnMsgUraA(WPARAM wParam, LPARAM
lParam){
>  PCOPYDATASTRUCT pcds;
>  //
>  pcds = (PCOPYDATASTRUCT)lParam;
>  //
>  if (pcds->dwData == MYID){
>   ctl->FireMensagem((long)((MYREC

*)(pcds->lpData))->chn,(LPCTSTR)((MYREC
Quote:
> *)(pcds->lpData))->msg);
>  }
>  //
>  return TRUE;
> }

////////////////////////////////////////////////////////////////////////
////
Quote:
> /////////////////////////////////////////////////////////////////
> like: ON_MESSAGE(WM_COPYDATA, OnMsgUraA)

////////////////////////////////////////////////////////////////////////
////

- Show quoted text -

Quote:
> /////////////////////////////////////////////////////////////////

> on VB I use this way:

> MyControl.MandaMensagemA(ControlerhWnd, 2, "Test using interprocess
> Comunication ...")

> but (when is a diferent instance I receive this on VB:


> To get the hWnd of instance I create an assistant window.

> Any Ideas ?????

> How Can I correct this ???

> Very thanks,

> Danilo ...



Sat, 26 Feb 2005 05:18:57 GMT  
 WM_COPYDATA Problems (urgent) ...
Yes, I has resolved this issue declaring the MYREC this way:

typedef struct tagMYREC{
 long chn;
 char msg[100];

Quote:
} MYREC;

Very thanks,

Danilo.



Quote:
> WM_COPYDATA in your case successfully transfers the 32-bit value of BSTR
> pointer to the other process, but of course this pointer is meaningless
> there. If you want to transfer the string with WM_COPYDATA, you need to
> serialize all the fields into one buffer, and set up this buffer in
> COPYDATASTRUCT.

> In other words, the data in COPYDATASTRUCT should not itself contain any
> pointers - WM_COPYDATA does not know they are pointers and doesn't
> trasfer any pointed-to memory.

> Why don't you use COM mechanisms? Your components could, for example,
> register themselves in the ROT and thus discover each other. COM
> transparently marshals BSTRs between processes practically without any
> effort on your part.
> --
> With best wishes,
>     Igor Tandetnik

> "For every complex problem, there is a solution that is simple, neat,
> and wrong." H.L. Mencken



> > Hello friends, I'm having problems during run time using WM_COPYDATA
> > message.
> > The Issue is this:

> > I have an OCX, that have the code to send, and receive this
> WM_COPYDATA
> > message, and usually this OCX is instancied in 5 programs in real
> time. Well
> > when I'm debuging from one instance to herself, OK works right, but
> from one
> > instance to another I lose my data!!!!!!!
> > this is the code to send the message:

> ////////////////////////////////////////////////////////////////////////
> ////
> > //////////////////////////////////////////////////////////////////
> > long CAlcUraCtrl::MandaMensagemA(long hWnd, long pCanal, BSTR
> pMensagem){
> > COPYDATASTRUCT cds;
> >  MYREC   mr;
> >  //
> >  mr.chn = pCanal;
> >  mr.msg = pMensagem;
> >  //
> >  cds.dwData = MYID;
> >  cds.cbData = sizeof(mr);
> >  cds.lpData = &mr;
> >  //
> >  ::SendMessage((HWND)hWnd,WM_COPYDATA,(WPARAM)pCanal,(LPARAM)&cds);
> > }

> ////////////////////////////////////////////////////////////////////////
> ////
> > ///////////////////////////////////////////////////////////////////

> > where MYREC is this:

> ////////////////////////////////////////////////////////////////////////
> ////
> > ///////////////////////////////////////////////////////////////////
> > typedef struct tagMYREC{
> >  long chn;
> >  BSTR msg;
> > } MYREC;

> ////////////////////////////////////////////////////////////////////////
> ////
> > //////////////////////////////////////////////////////////////////

> > And the receiver code is this:

> ////////////////////////////////////////////////////////////////////////
> ////
> > //////////////////////////////////////////////////////////////////
> > LRESULT JanelaAuxiliarEventos::OnMsgUraA(WPARAM wParam, LPARAM
> lParam){
> >  PCOPYDATASTRUCT pcds;
> >  //
> >  pcds = (PCOPYDATASTRUCT)lParam;
> >  //
> >  if (pcds->dwData == MYID){
> >   ctl->FireMensagem((long)((MYREC
> *)(pcds->lpData))->chn,(LPCTSTR)((MYREC
> > *)(pcds->lpData))->msg);
> >  }
> >  //
> >  return TRUE;
> > }

> ////////////////////////////////////////////////////////////////////////
> ////
> > /////////////////////////////////////////////////////////////////
> > like: ON_MESSAGE(WM_COPYDATA, OnMsgUraA)

> ////////////////////////////////////////////////////////////////////////
> ////
> > /////////////////////////////////////////////////////////////////

> > on VB I use this way:

> > MyControl.MandaMensagemA(ControlerhWnd, 2, "Test using interprocess
> > Comunication ...")

> > but (when is a diferent instance I receive this on VB:


> > To get the hWnd of instance I create an assistant window.

> > Any Ideas ?????

> > How Can I correct this ???

> > Very thanks,

> > Danilo ...



Sat, 26 Feb 2005 21:19:08 GMT  
 
 [ 3 post ] 

 Relevant Pages 

1. Marshaling problem using WM_COPYDATA and byte[]

2. Problem in sending WM_COPYDATA message

3. Problem with WM_COPYDATA

4. Still got problems with WM_COPYDATA message !

5. WM_COPYDATA can I do it in C#?

6. WM_COPYDATA

7. how to use WM_COPYDATA ?

8. SendMessage/WM_COPYDATA

9. Weird WM_COPYDATA behaviour

10. WM_COPYDATA

11. WM_PASTE and WM_COPYDATA

12. WM_COPYDATA and WM_PASTE.

 

 
Powered by phpBB® Forum Software