Jag försöker att skicka kommandon till en annan applikation med WM_COPYDATA men jag kan inte få det att fungera, vad gör jag för fel?SendMessage
Private Structure CopyData
Public dwData As String
Public cbData As Integer
Public lpData As IntPtr
End Structure
Private Declare Auto Function SendMessage Lib "user32" _
(ByVal hWnd As IntPtr, _
ByVal Msg As Integer, _
ByVal wParam As Integer, _
ByRef lParam As CopyData) As Boolean
Private Declare Auto Function FindWindow Lib "user32" _
(ByVal lpClassName As String, _
ByVal lpWindowName As String) As IntPtr
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim ClientWindow As IntPtr = FindWindow(Nothing, Form1.WindowName)
' make sure we found an active client window
If Not ClientWindow.Equals(IntPtr.Zero) Then
' if there is text to send
If TextBox1.Text.Length > 0 Then
Dim message As String = TextBox1.Text & "/0"
Dim data As CopyData
' set up the data...
data.dwData = "1"
data.lpData = Marshal.StringToHGlobalAuto(message)
data.cbData = message.Length * Marshal.SystemDefaultCharSize
' send the data
Form1.SendMessage(ClientWindow, WM_COPYDATA, 0, data)
' free the pointer...
Marshal.FreeHGlobal(data.lpData)
End If
Else
MessageBox.Show("Could Not Find Active Client Window.")
End If
End Sub