Private
Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Integer, ByVal wMsg As Integer, ByVal wParam As Integer, ByRef lParam As any) As integerPrivate Declare Function SendMessageLong Lib "user32" Alias "SendMessageA" (ByVal hwnd As Integer, ByVal wMsg As Integer, ByVal wParam As Integer, ByVal lParam As any) As integer
that was how i declared them in VB6
this is how i am declaring them in vb .net 2005
Private
Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Integer, ByVal wMsg As Integer, ByVal wParam As Integer, ByRef lParam As IntPtr) As IntPtr Private Declare Function SendMessageLong Lib "user32" Alias "SendMessageA" (ByVal hwnd As Integer, ByVal wMsg As Integer, ByVal wParam As Integer, ByVal lParam As IntPtr) As IntPtrbut when i use the sendmessage function i get this error
SendMessage(hTT, TTM_ADDTOOL, 0, TI)
'TI' can be converted to IntPtr. I ahve also tried integer and longs(int64) those didn't work either. I am at a loss help please.

"user32" SendMessage (....)
TheViewMaster
I have tried that Iparam as integer, int64, string. Now i have it as an object but i am getting this message:
A call to PInvoke function 'ShippingSuite!ShippingSuite.clsToolTip::SendMessageLong' has unbalanced the stack. This is likely because the managed PInvoke signature does not match the unmanaged target signature. Check that the calling convention and parameters of the PInvoke signature match the target unmanaged signature.
the 'TI' is a user defined structure and i am now wondering if that is where the problem is orignating from....
maxascent
Got this info using Lutz Roeder's .NET Reflector:
Tony
WV John
Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" _
(ByVal hWnd As Integer, ByVal wMsg As Integer, _
ByVal wParam As Integer, ByRef lParam As Integer) As Integer
venup
Here are some relevant pieces I chopped out of a working program
that uses the SendMessage API.
<System.Runtime.InteropServices.StructLayout(System.Runtime.InteropServices.LayoutKind.Sequential)> _
Private Structure FORMATRANGE
Public hdc As IntPtr
Public hdcTarget As IntPtr
Public rc As RECT
Public rcPage As RECT
Public chrg As CHARRANGE
End Structure
Dim fmtRange As FORMATRANGE
fmtRange.chrg = cRange
fmtRange.hdc = hdc
fmtRange.hdcTarget = hdc
fmtRange.rc = rectToPrint
fmtRange.rcPage = rectToPrint
Dim wparam As New IntPtr(1) ' CHANGE BACK TO 1, 0 = just figure 1 = figure and print
Dim lparam As New IntPtr(0) ' = IntPtr.Zero
lparam = System.Runtime.InteropServices.Marshal.AllocCoTaskMem(System.Runtime.InteropServices.Marshal.SizeOf(fmtRange))
System.Runtime.InteropServices.Marshal.StructureToPtr(fmtRange, lparam, False)
'Change handle here to your richtextbox to print from.
res = SendMessage(RichTextBox1.Handle, 1081, wparam, lparam)
System.Runtime.InteropServices.Marshal.FreeCoTaskMem(lparam)
DevDiver
Mateusz Rajca
Hope it works out :)