Structure posting
-
Hi all, I am trying to post a structure to a Created Worker Thread !All the members of the structure are BSTRs.I am defining all the members of the structure & posting the structure as the WPARAM of PostThreadMessage.(I am typecasting the pointer to structure as WPARAM). The problem is I am able to post the structure with all the member values correctly !But while getting that Thread Message & retrieving the values of the members some of the Member values r received wrongly !I have used SysAllocString while getting back the values of members ! How can I rectify the problem ! Thanx! Y.Yamini Devi
-
Hi all, I am trying to post a structure to a Created Worker Thread !All the members of the structure are BSTRs.I am defining all the members of the structure & posting the structure as the WPARAM of PostThreadMessage.(I am typecasting the pointer to structure as WPARAM). The problem is I am able to post the structure with all the member values correctly !But while getting that Thread Message & retrieving the values of the members some of the Member values r received wrongly !I have used SysAllocString while getting back the values of members ! How can I rectify the problem ! Thanx! Y.Yamini Devi
Yamini, It sounds like you are passing in a pointer to the structure properly, and some of the data is correct. But since the interface thread is still running, perhaps the values that were originally stored in the structure have been changed before you got a chance to read them? (Just a side note to be sure that you use a Critical Section or a Mutex to ensure that one thread is not writing new data to the structure at the same time the other is trying to read it.) I'm assuming that you do cast the WPARAM back to the correct structure pointer when the message is received by the worker thread. If checking on this stuff doesn't help, reply to the post, and I'll try to think of other reasons this may be happening. Jeff
-
Yamini, It sounds like you are passing in a pointer to the structure properly, and some of the data is correct. But since the interface thread is still running, perhaps the values that were originally stored in the structure have been changed before you got a chance to read them? (Just a side note to be sure that you use a Critical Section or a Mutex to ensure that one thread is not writing new data to the structure at the same time the other is trying to read it.) I'm assuming that you do cast the WPARAM back to the correct structure pointer when the message is received by the worker thread. If checking on this stuff doesn't help, reply to the post, and I'll try to think of other reasons this may be happening. Jeff
I got the following message in reply: Thanx for the ideas !I created a worker thread .I am posting message to this worker thread only ! As you said I am passing the pointer to structure as WPARAM of the message !Now, in the ThreadProc of this worker thread I am typecasting the WPARAM of the message to the structure pointer and retrieve the members of the structure !Here only I am receiving the wrong value for some data members(Of the 11 members the last 4 member values are wrong !)What can be the problem ?I had tried with Mutex & critical section.Still the same problem exists ! How can I overcome this problem ? Regards, Y.Yamini Devi
-
I got the following message in reply: Thanx for the ideas !I created a worker thread .I am posting message to this worker thread only ! As you said I am passing the pointer to structure as WPARAM of the message !Now, in the ThreadProc of this worker thread I am typecasting the WPARAM of the message to the structure pointer and retrieve the members of the structure !Here only I am receiving the wrong value for some data members(Of the 11 members the last 4 member values are wrong !)What can be the problem ?I had tried with Mutex & critical section.Still the same problem exists ! How can I overcome this problem ? Regards, Y.Yamini Devi
Yamini, It depends on how you know the members are wrong. If you are using a byte index into the structure and coming up with the wrong values, or if you are looking into memory locations directly, then the problem may be how the structure is defined. If you don't tell the compiler to pack the structure to 1 byte values then when it builds the structure it may pad spaces onto the end of intermediate values to get the 'correct' block sizes. If you have strutures within the defined 'communication' structure, this problem can be compounded. Check that you use the compiler directive "#pragma pack (1)" around your structures to be sure that the compiler is not adding additional empty bytes. Once all the structures are defined you can use "#pragma pack ()" to return the pack value to its previous setting. Just a thought Jeff