Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. Structure posting

Structure posting

Scheduled Pinned Locked Moved C / C++ / MFC
4 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • Y Offline
    Y Offline
    yamini
    wrote on last edited by
    #1

    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

    J 1 Reply Last reply
    0
    • Y yamini

      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

      J Offline
      J Offline
      Jeff Naber
      wrote on last edited by
      #2

      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

      J 1 Reply Last reply
      0
      • J Jeff Naber

        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

        J Offline
        J Offline
        Jeff Naber
        wrote on last edited by
        #3

        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

        J 1 Reply Last reply
        0
        • J Jeff Naber

          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

          J Offline
          J Offline
          Jeff Naber
          wrote on last edited by
          #4

          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

          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups