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. GetMessage

GetMessage

Scheduled Pinned Locked Moved C / C++ / MFC
helpdata-structuresperformancequestion
5 Posts 3 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.
  • W Offline
    W Offline
    wilche
    wrote on last edited by
    #1

    Hi Everyone, I need some help!!! I have been retrieving my messages from the message queue in my thread using the GetMessage(). I've placed the message inside the MSG structure and retrieve the messaage contents by referencing msg.wParam. msg.wParam is an UINT value that represents the address of msg content, in this case, a dynamically allocated char * pointer. After using this string, I wanted to deallocate the memory for this char *ptr, doing this. delete (char *) msg.wParam; It compiles but didn't work. As suspected, msg.wParam isn't a ptr, it's an address! So I tried this. char *tmp; tmp = (char *) msg.wParam; delete tmp; It compiles Same problem. So what can I do? Everytime a new msg comes, the information in msg.wParam is rewritten. But I'm pretty sure that the memory allocation remains! :confused: Any help on this problem is greatly appreciated! Thanks! wilche

    J 1 Reply Last reply
    0
    • W wilche

      Hi Everyone, I need some help!!! I have been retrieving my messages from the message queue in my thread using the GetMessage(). I've placed the message inside the MSG structure and retrieve the messaage contents by referencing msg.wParam. msg.wParam is an UINT value that represents the address of msg content, in this case, a dynamically allocated char * pointer. After using this string, I wanted to deallocate the memory for this char *ptr, doing this. delete (char *) msg.wParam; It compiles but didn't work. As suspected, msg.wParam isn't a ptr, it's an address! So I tried this. char *tmp; tmp = (char *) msg.wParam; delete tmp; It compiles Same problem. So what can I do? Everytime a new msg comes, the information in msg.wParam is rewritten. But I'm pretty sure that the memory allocation remains! :confused: Any help on this problem is greatly appreciated! Thanks! wilche

      J Offline
      J Offline
      John M Drescher
      wrote on last edited by
      #2

      try delete [] reinterpret_cast(msg.wParam);

      R W 2 Replies Last reply
      0
      • J John M Drescher

        try delete [] reinterpret_cast(msg.wParam);

        R Offline
        R Offline
        Rama Krishna Vavilala
        wrote on last edited by
        #3

        John M. Drescher wrote: delete [] reinterpret_cast(msg.wParam); Oops I missed that in my reply. Thanks:)

        1 Reply Last reply
        0
        • J John M Drescher

          try delete [] reinterpret_cast(msg.wParam);

          W Offline
          W Offline
          wilche
          wrote on last edited by
          #4

          Thanks! that works! uh could you explain why it works? greatly appreciated! wilche

          J 1 Reply Last reply
          0
          • W wilche

            Thanks! that works! uh could you explain why it works? greatly appreciated! wilche

            J Offline
            J Offline
            John M Drescher
            wrote on last edited by
            #5

            delete (char *) msg.wParam; This deletes only 1 char not an array of char. Add [] to delete arrays. The reinterpret_cast<> is a c++ way of casting. John

            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