"user32" SendMessage (....)

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 integer

Private 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 IntPtr

but 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.




Answer this question

"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:

    <DllImport("user32.dll", CharSet:=CharSet.Auto)> _
    Public Shared Function SendMessage(ByVal hWnd As HandleRef, ByVal msg As Integer, ByVal wParam As Integer, ByVal lParam As TOOLINFO_T) As IntPtr
    
    <StructLayout(LayoutKind.Sequential, CharSet:=CharSet.Auto)> _
    Public Class TOOLINFO_TOOLTIP
       ' Methods
       Public Sub New()
    
       ' Fields
       Public cbSize As Integer
       Public hinst As IntPtr
       Public hwnd As IntPtr
       Public lParam As IntPtr
       Public lpszText As IntPtr
       Public rect As RECT
       Public uFlags As Integer
       Public uId As IntPtr
    End Class
    

    Tony


  • WV John

    ChristianBG wrote:

    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 integer

    Private 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 IntPtr

    but 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.

    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

    I have been looking at the code and it looks as if it would work, i am not sure were to put it though. I had made a new class for it but that didn't work. thank you i just also looked in that .ner reflector, when i get some time i am going to play with it seem like a helpful tool

  • Mateusz Rajca

    Try typecasting it into UInt32 , cause thats what lParam is..

    Hope it works out :)


  • "user32" SendMessage (....)