title: SendMessage - Passing a string from VB6 to VB.NET
body: <p>Good afternoon,</p>
  
  <p>I am attempting to use SendMessage to pass a string from a VB6 EXE, to a .NET 2013 EXE.  I know that the message is getting in to the .NET EXE, because I'm able to set a breakpoint on it and it comes up when I call SendMessage from the VB6 EXE.  The problem I am having is retrieving the string.</p>
  
  <p>This is how I am attempting to do it:</p>
  
  <p>VB6 Code:</p>
  
  <pre><code>Option Explicit
  
  Private Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" (dest As Any, Source As Any, ByVal bytes As Long)
  Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
  Private Declare Function SendMessage Lib "user32.dll" Alias "SendMessageA" (ByVal hwnd As Long, ByVal msg As Long, wParam As Long, lParam As Any) As Long
  
  Private Const APPVIEWER_OPEN = &amp;H400
  
  Private Sub Command1_Click()
    Dim hwndAppViewer As Long
    Dim bytBuffer(1 To 255) As Byte
    Dim sParams As String
    Dim lStringAddress As Long
  
    hwndAppViewer = FindWindow(vbNullString, "DotNetReceiver")
  
    If hwndAppViewer &gt; 0 Then
      sParams = "STRINGDATA"
      CopyMemory bytBuffer(1), sParams, Len(sParams)
      lStringAddress = VarPtr(bytBuffer(1))
      SendMessage hwndAppViewer, APPVIEWER_OPEN, Me.hwnd, lStringAddress
    End If
  End Sub
  </code></pre>
  
  <p>Here is the .NET code:</p>
  
  <pre><code>Imports System.Runtime.InteropServices
  
  Public Class Form1
    Protected Overrides Sub WndProc(ByRef m As Message)
      Dim sPolicyInformation As String
  
      If m.Msg = &amp;H400 Then
        sPolicyInformation = Marshal.PtrToStringAnsi(m.LParam)
      Else
        MyBase.WndProc(m)
      End If
    End Sub
  End Class
  </code></pre>
  
  <p>The problem comes when I try and retrieve the string.  I am getting a blank string.  I noticed that the number in the VB6 lStringAddress and the number in .NET m.lParam are completely different, so I must be missing something about how I'm passing the address through lParam.</p>
  
  <p>Any ideas what I might be missing?</p>
  
  <p>Thank you.</p>