Me and a friend have been trying to get this working in VB.NET for a few days now, we've tried pretty much everything we could think of, and it just wont work. Any idea whats causing it to not work?:
<DllImport("user32.dll", SetLastError:=True, CharSet:=CharSet.Auto)> _
Private Shared Function FindWindow( _
ByVal lpClassName As String, _
ByVal lpWindowName As String) As IntPtr
End Function
<DllImport("user32.dll", CharSet:=CharSet.Auto)> _
Public Shared Function SendMessage( _
ByVal hwnd As IntPtr, _
ByVal msg As Integer, _
ByVal wparam As IntPtr, _
ByVal lparam As IntPtr) As IntPtr
End Function
<StructLayout(LayoutKind.Sequential)> _
Private Structure CopyData
Public dwData As IntPtr
Public cbData As Integer
Public lpData As IntPtr
End Structure
Private Const WM_COPYDATA As Integer = &H4A
Public Function SendString(ByVal s As String) As Integer
Try
Dim CDS As CopyData, Result As Integer
Dim Str As String = s
CDS.dwData = AudiosurfHandle
Str &= Chr(0)
CDS.cbData = Str.Length + 1
CDS.lpData = Marshal.AllocHGlobal(Str.Length)
CDS.lpData = Marshal.StringToHGlobalAnsi(Str)
Dim iPtr As IntPtr = Marshal.AllocHGlobal(Marshal.SizeOf(CDS))
Marshal.StructureToPtr(CDS, iPtr, True)
Result = SendMessage(AudiosurfHandle, WM_COPYDATA, IntPtr.Zero, iPtr).ToInt32
Marshal.FreeHGlobal(CDS.lpData)
Marshal.FreeHGlobal(iPtr)
Return Result
Catch ex As Exception
MessageBox.Show(ex.ToString, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
Application.Exit()
Return 0
End Try
End Function
Also, we used
this reference page too.