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. The Lounge
  3. Passing a string with PostMessage

Passing a string with PostMessage

Scheduled Pinned Locked Moved The Lounge
performancequestion
2 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.
  • J Offline
    J Offline
    Jason Douglas
    wrote on last edited by
    #1

    I'm trying to pass some sort of character string with PostMessage or SendMessage (as the wparam). I got it to work, but I used a CString* and I'm not very happy with that solution. Two reasons: it's dangerous to play with memory across classes this way; and I need to call SendMessage to make sure the proper memory is removed (asynchronous nature of PostMessage causes leaks). Is there a better way to pass a string parameter to a PostMessage call? Thanks, Jason :confused:

    O 1 Reply Last reply
    0
    • J Jason Douglas

      I'm trying to pass some sort of character string with PostMessage or SendMessage (as the wparam). I got it to work, but I used a CString* and I'm not very happy with that solution. Two reasons: it's dangerous to play with memory across classes this way; and I need to call SendMessage to make sure the proper memory is removed (asynchronous nature of PostMessage causes leaks). Is there a better way to pass a string parameter to a PostMessage call? Thanks, Jason :confused:

      O Offline
      O Offline
      Oz Solomon
      wrote on last edited by
      #2

      First of all, the lounge is not the place for these type of posts. You're better off asking this question in one of the forums. But since we're on the subject, let's discuss a few choices. You can either: -- char *pStr = new char[200] strcpy(pStr, "hello world"); ... SendMessage(hWnd, (WPARAM)pStr, NULL) In the message handler you simply char * const pStr = (char *)wParam; delete [] pStr; -- As an alternative, if you strings are <255 characters, you can use AddAtom() and DeleteAtom() to have Windows manage memory for you. Use GlobalAddAtom() and GlobalDeleteAtom() if you're sending the message to a window of a different application. -Oz --- Grab WndTabs from http://www.wndtabs.com to make your VC++ experience that much more comfortable...

      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