I have a server application in VB.NET which is trying to send a text message to a textbox in a window in a client application, written in classic VB (I have no control over the client code). I'm using IPC, specifically the "SendMessageTimeout" PInvoke.
I want to send "Hello World" to the textbox in the client. When I run the app, it sends "H" (but doesn't send "ello World"). If I change the message to "Test 1-2-3", it sends "T" (but not "est 1-2-3").
How can I get the whole message sent?
Code below ("lParam" is the string I want to send):
Private Function fSendString(ByVal hwnd As IntPtr, ByVal uMsg As IntPtr, ByVal wParam As IntPtr, ByVal lParam As String) As IntPtr
Try
Dim lResult As IntPtr
Dim GCH As GCHandle = GCHandle.Alloc(lParam, GCHandleType.Pinned)
Dim pS As IntPtr = GCH.AddrOfPinnedObject
If SendMessageTimeout(hwnd, uMsg, wParam, pS, 0, 25, lResult) Then
'If this function returns true, the result holds the return value.
fSendString = lResult
End If
GCH.Free()
Catch ex As Exception
MsgBox("fSendString(): " & ex.ToString)
fSendString = Nothing
End Try
Return fSendString
End Function
As far as the app is concerned, everything is running fine - no errors at all. But obviously it's not working. :)