
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)
////////////////////////////////////////////////////////////////////////
////
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 ...