Message cross threads
-
hi, in one procedure I post message to thread with
wParam
, the thread accepted my message, but wParam is corrupted. Here is the code: In the procedureMsgParam \*pSendParam=new MsgParam; pSendParam->pBuf=pBuf; pSendParam->nLen=nLen; PostThreadMessage(tid,WM\_HYDRO\_RXD\_ARRIVAL,(WPARAM)pSendParam,0);
In thread Function
case WM_HYDRO_RXD_ARRIVAL:
pRecParam=(MsgParam*)msg.wParam;before
PostThreadMessage
,pSendParam
is correct(in this case, it'sf5f5090574a05200
), but incase WM_HYDRO_RXD_ARRIVAL
, the value is corrupted as44bf4a5f01000000
, How to transfer data correctly? Extreme programming. Do the No.1 -
hi, in one procedure I post message to thread with
wParam
, the thread accepted my message, but wParam is corrupted. Here is the code: In the procedureMsgParam \*pSendParam=new MsgParam; pSendParam->pBuf=pBuf; pSendParam->nLen=nLen; PostThreadMessage(tid,WM\_HYDRO\_RXD\_ARRIVAL,(WPARAM)pSendParam,0);
In thread Function
case WM_HYDRO_RXD_ARRIVAL:
pRecParam=(MsgParam*)msg.wParam;before
PostThreadMessage
,pSendParam
is correct(in this case, it'sf5f5090574a05200
), but incase WM_HYDRO_RXD_ARRIVAL
, the value is corrupted as44bf4a5f01000000
, How to transfer data correctly? Extreme programming. Do the No.1 -
hi, in one procedure I post message to thread with
wParam
, the thread accepted my message, but wParam is corrupted. Here is the code: In the procedureMsgParam \*pSendParam=new MsgParam; pSendParam->pBuf=pBuf; pSendParam->nLen=nLen; PostThreadMessage(tid,WM\_HYDRO\_RXD\_ARRIVAL,(WPARAM)pSendParam,0);
In thread Function
case WM_HYDRO_RXD_ARRIVAL:
pRecParam=(MsgParam*)msg.wParam;before
PostThreadMessage
,pSendParam
is correct(in this case, it'sf5f5090574a05200
), but incase WM_HYDRO_RXD_ARRIVAL
, the value is corrupted as44bf4a5f01000000
, How to transfer data correctly? Extreme programming. Do the No.1You are developing on Win64? Wow :cool: Your problem sounds a bit strange. It should work as you described, I can't find anything conspicuous in your code. I would suppose a subtle side effect: - Are you sure the value of WM_HYDRO_RXD_ARRIVAL is unique and you are not accidently catching the wrong message? - Are you sure _W64 is always defined and really all data types are used as 64 bit types? - Did you monitor any other side effects that look like memory corruption occuring somewhere in your app? - Does the same problem appear in a small test app? (Hm the above looks a bit like the generic "are you sure the power cable is plugged in" hotline answer :-O ) Good luck! -- Daniel Lohmann http://www.losoft.de (Hey, this page is worth looking! You can find some free and handy NT tools there :-D )
-
hi, in one procedure I post message to thread with
wParam
, the thread accepted my message, but wParam is corrupted. Here is the code: In the procedureMsgParam \*pSendParam=new MsgParam; pSendParam->pBuf=pBuf; pSendParam->nLen=nLen; PostThreadMessage(tid,WM\_HYDRO\_RXD\_ARRIVAL,(WPARAM)pSendParam,0);
In thread Function
case WM_HYDRO_RXD_ARRIVAL:
pRecParam=(MsgParam*)msg.wParam;before
PostThreadMessage
,pSendParam
is correct(in this case, it'sf5f5090574a05200
), but incase WM_HYDRO_RXD_ARRIVAL
, the value is corrupted as44bf4a5f01000000
, How to transfer data correctly? Extreme programming. Do the No.1the code is absolutely incorrect. try to send an int int i=5; PostThreadMessage(tid,WM_HYDRO_RXD_ARRIVAL,(WPARAM)i,0); it will be OK. when u pass an object created by new, normally it can not be passed to another thread in the simple way. i don't know how to do it, but i did similar thing in COM, if u know COM, try same idea that how COM passes object to another COM (they are in 2 threads). good luck. includeh10
-
the code is absolutely incorrect. try to send an int int i=5; PostThreadMessage(tid,WM_HYDRO_RXD_ARRIVAL,(WPARAM)i,0); it will be OK. when u pass an object created by new, normally it can not be passed to another thread in the simple way. i don't know how to do it, but i did similar thing in COM, if u know COM, try same idea that how COM passes object to another COM (they are in 2 threads). good luck. includeh10
What? :wtf::omg: Sorry, includeh10, but you seem to completly misunderstood the concept of threads. You can pass pointers between threads as long as you make sure they reside in the same process. All threads inside a process share the same address space, therefore any address reference is valid and accessable by every thread. Actually this easiness of inter-thread communication is the main reason we use threads instead of processes. COM puts a lot of "magic stuff" (like apartments, free threaded marshaller, ...) around this, because it has to guarantee that it even works if both thread reside in different processes or even on different machines. -- Daniel Lohmann http://www.losoft.de (Hey, this page is worth looking! You can find some free and handy NT tools there :-D )
-
BTW: Your E-Mail address seems to be incorrect. I got an "Undeliverable Mail" message for steven_wng@sina.com on my previous post. Hope you check the forum as well :-) -- Daniel Lohmann http://www.losoft.de (Hey, this page is worth looking! You can find some free and handy NT tools there :-D )
-
What? :wtf::omg: Sorry, includeh10, but you seem to completly misunderstood the concept of threads. You can pass pointers between threads as long as you make sure they reside in the same process. All threads inside a process share the same address space, therefore any address reference is valid and accessable by every thread. Actually this easiness of inter-thread communication is the main reason we use threads instead of processes. COM puts a lot of "magic stuff" (like apartments, free threaded marshaller, ...) around this, because it has to guarantee that it even works if both thread reside in different processes or even on different machines. -- Daniel Lohmann http://www.losoft.de (Hey, this page is worth looking! You can find some free and handy NT tools there :-D )
i am pretty sure that an object can be past from one COM to another even 2 COM are in the same process (or create by same process). as i said, i never use threads in this way, but i don't think the code would work. anyway, do further test to get right answer. good luck includeh10
-
hi, in one procedure I post message to thread with
wParam
, the thread accepted my message, but wParam is corrupted. Here is the code: In the procedureMsgParam \*pSendParam=new MsgParam; pSendParam->pBuf=pBuf; pSendParam->nLen=nLen; PostThreadMessage(tid,WM\_HYDRO\_RXD\_ARRIVAL,(WPARAM)pSendParam,0);
In thread Function
case WM_HYDRO_RXD_ARRIVAL:
pRecParam=(MsgParam*)msg.wParam;before
PostThreadMessage
,pSendParam
is correct(in this case, it'sf5f5090574a05200
), but incase WM_HYDRO_RXD_ARRIVAL
, the value is corrupted as44bf4a5f01000000
, How to transfer data correctly? Extreme programming. Do the No.1Have you tried passing pSendParam through the LPARAM parameter?
PostThreadMessage(tid,WM_HYDRO_RXD_ARRIVAL,0,(LPARAM)pSendParam);
and changing your thread to this:pRecParam=(MsgParam*)msg.lParam;
Kelly Herald Software Developer Micronpc, LLC -
the code is absolutely incorrect. try to send an int int i=5; PostThreadMessage(tid,WM_HYDRO_RXD_ARRIVAL,(WPARAM)i,0); it will be OK. when u pass an object created by new, normally it can not be passed to another thread in the simple way. i don't know how to do it, but i did similar thing in COM, if u know COM, try same idea that how COM passes object to another COM (they are in 2 threads). good luck. includeh10