wawang
5/30/2007 5:39:00 AM
Hi Dave,
The string will not need to manually pinned, the marshaller should take
care of it.
I think it's related to how's your C DLL implemented. Would you please tell
us how is the function exported from your DLL?
Here's some code to demonstrate how to use SendMessage and WM_SETTEXT to
change a Notepad window's caption:
Private Declare Auto Function FindWindow Lib "user32" (ByVal className
As String, ByVal windowName As String) As IntPtr
Private Declare Auto Function SendMessage Lib "user32" (ByVal hwnd As
IntPtr, ByVal msg As Integer, ByVal wParam As Integer, ByVal lParam As
String) As IntPtr
Private Declare Function SendMessageStr Lib "user32" Alias
"SendMessageA" (ByVal hwnd As IntPtr, ByVal msg As Integer, ByVal wParams
As Integer, ByVal lParam As String) As Integer
Const WM_SETTEXT As Integer = &HC
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
Dim h As IntPtr = FindWindow("Notepad", Nothing)
If h <> IntPtr.Zero Then
SendMessage(h, WM_SETTEXT, 0, DateTime.Now.ToString())
SendMessageStr(h, WM_SETTEXT, 0, DateTime.Now.ToString)
End If
End Sub
Please note the two declarations, both should work correctly.
Regards,
Walter Wang (wawang@online.microsoft.com, remove 'online.')
Microsoft Online Community Support
==================================================
When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.
==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.