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
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. General Programming
  3. Visual Basic
  4. How to send message contain a string ?

How to send message contain a string ?

Scheduled Pinned Locked Moved Visual Basic
c++helptutorialquestion
5 Posts 2 Posters 1 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.
  • K Offline
    K Offline
    Ky Nam
    wrote on last edited by
    #1

    In managed code , i send a message to native application : Dim s As String = "text that i want to send" Dim GC As GCHandle = GCHandle.Alloc(s) SendMessage( hwnd , MsgId , wParam , GC ) GC.Free() In native code , i want to display a message box with text got from above message : LRESULT WndProc( HWND hWnd, UINT Msg, WPARAM wParam, LPARAM lParam ) { MessageBox(hWnd, (LPTSTR)lParam, L"Caption", MB_OKCANCEL | MB_ICONQUESTION | MB_APPLMODAL); } But i can not get text with : (LPTSTR)lParam Please help me to know why this code doesn't work , and how to do it ? Thank you

    L 1 Reply Last reply
    0
    • K Ky Nam

      In managed code , i send a message to native application : Dim s As String = "text that i want to send" Dim GC As GCHandle = GCHandle.Alloc(s) SendMessage( hwnd , MsgId , wParam , GC ) GC.Free() In native code , i want to display a message box with text got from above message : LRESULT WndProc( HWND hWnd, UINT Msg, WPARAM wParam, LPARAM lParam ) { MessageBox(hWnd, (LPTSTR)lParam, L"Caption", MB_OKCANCEL | MB_ICONQUESTION | MB_APPLMODAL); } But i can not get text with : (LPTSTR)lParam Please help me to know why this code doesn't work , and how to do it ? Thank you

      L Offline
      L Offline
      Luc Pattyn
      wrote on last edited by
      #2

      Hi, within a single process you need to obtain a GCHandle with GCHandleType.Pinned so the GC can not move the object anymore; then you get the pointer through GCHandle.AddrOfPinnedObject, and that will be your lParam. passing strings to another process does not work that way, since the pointer only means something to the process that owns the string. More code is needed to allocate, then write, memory in the other process. :)

      Luc Pattyn [Forum Guidelines] [My Articles]


      this weeks tips: - make Visual display line numbers: Tools/Options/TextEditor/... - show exceptions with ToString() to see all information - before you ask a question here, search CodeProject, then Google


      K 1 Reply Last reply
      0
      • L Luc Pattyn

        Hi, within a single process you need to obtain a GCHandle with GCHandleType.Pinned so the GC can not move the object anymore; then you get the pointer through GCHandle.AddrOfPinnedObject, and that will be your lParam. passing strings to another process does not work that way, since the pointer only means something to the process that owns the string. More code is needed to allocate, then write, memory in the other process. :)

        Luc Pattyn [Forum Guidelines] [My Articles]


        this weeks tips: - make Visual display line numbers: Tools/Options/TextEditor/... - show exceptions with ToString() to see all information - before you ask a question here, search CodeProject, then Google


        K Offline
        K Offline
        Ky Nam
        wrote on last edited by
        #3

        Thank you , i will try to write "more code"

        L 1 Reply Last reply
        0
        • K Ky Nam

          Thank you , i will try to write "more code"

          L Offline
          L Offline
          Luc Pattyn
          wrote on last edited by
          #4

          Hi, you may want to have a look at my TrayIconBuster article; it has an LP_Process class that deals with this (it is in C#, same things can be done in VB.NET). :)

          Luc Pattyn [Forum Guidelines] [My Articles]


          this weeks tips: - make Visual display line numbers: Tools/Options/TextEditor/... - show exceptions with ToString() to see all information - before you ask a question here, search CodeProject, then Google


          K 1 Reply Last reply
          0
          • L Luc Pattyn

            Hi, you may want to have a look at my TrayIconBuster article; it has an LP_Process class that deals with this (it is in C#, same things can be done in VB.NET). :)

            Luc Pattyn [Forum Guidelines] [My Articles]


            this weeks tips: - make Visual display line numbers: Tools/Options/TextEditor/... - show exceptions with ToString() to see all information - before you ask a question here, search CodeProject, then Google


            K Offline
            K Offline
            Ky Nam
            wrote on last edited by
            #5

            Thank you again :)

            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