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. How to send CString with SendMessage

How to send CString with SendMessage

Scheduled Pinned Locked Moved C / C++ / MFC
questiontutorial
3 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.
  • V Offline
    V Offline
    Vassili
    wrote on last edited by
    #1

    Hi all, does anybody know what the exact syntax is for sending a CString variable with SendMessage? I have tried every thing you can imagine: UINT MyThread(LPVOID arg) { HWND hMain = (HWND) arg; CString text; text = "Hello"; SendMessage(hMain, WM_SEND_HELLO, 0, (LPARAM &) text); } LRESULT CMyDlg::OnSendHello(WPARAM wParam, LPARAM lParam) { CString* text = (CString *) lParam; return 0; } What is wrong with this code?

    P J 2 Replies Last reply
    0
    • V Vassili

      Hi all, does anybody know what the exact syntax is for sending a CString variable with SendMessage? I have tried every thing you can imagine: UINT MyThread(LPVOID arg) { HWND hMain = (HWND) arg; CString text; text = "Hello"; SendMessage(hMain, WM_SEND_HELLO, 0, (LPARAM &) text); } LRESULT CMyDlg::OnSendHello(WPARAM wParam, LPARAM lParam) { CString* text = (CString *) lParam; return 0; } What is wrong with this code?

      P Offline
      P Offline
      puzzolino
      wrote on last edited by
      #2

      Try correcting your SendMessage to this: SendMessage(hMain, WM_SEND_HELLO, 0, (LPARAM) &text); Maybe you need a LPCTSTR cast for &text, if it doesn't compile.

      1 Reply Last reply
      0
      • V Vassili

        Hi all, does anybody know what the exact syntax is for sending a CString variable with SendMessage? I have tried every thing you can imagine: UINT MyThread(LPVOID arg) { HWND hMain = (HWND) arg; CString text; text = "Hello"; SendMessage(hMain, WM_SEND_HELLO, 0, (LPARAM &) text); } LRESULT CMyDlg::OnSendHello(WPARAM wParam, LPARAM lParam) { CString* text = (CString *) lParam; return 0; } What is wrong with this code?

        J Offline
        J Offline
        John R Shaw
        wrote on last edited by
        #3

        It appears you want to send a pointer to a CString. Wrong: SendMessage(hMain, WM_SEND_HELLO, 0, (LPARAM &) text); Right: SendMessage(hMain, WM_SEND_HELLO, 0, (LPARAM) &text); Personly I recommend sending the address of the string instead of the address of a CString object. SendMessage(hMain, WM_SEND_HELLO, 0, (LPARAM)(LPCSTR)text); Trust in the code Luke. Yea right!

        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