troubleshooting Question

detect mouse click outside form

Avatar of peispud
peispudFlag for Canada asked on
Visual Basic.NET
7 Comments1 Solution2210 ViewsLast Modified:
Hi.   I am using VB.net 2005

The code below causes the following error.  I am having trouble with this.  I would appreciate your help.

"A call to PInvoke function 'WindowsApplication2!WindowsApplication2.Form1::GetAsyncKeyState' 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."
Public Class Form1
    Private Declare Function GetAsyncKeyState Lib "user32" (ByVal vKey As Long) As Integer
    Public Declare Function GetCursorPos Lib "user32" (ByRef lpPoint As PointAPI) As Boolean

    Structure PointAPI
        Public x As Integer ' Integer if you prefer
        Public y As Integer ' Integer if you prefer
    End Structure
    Private Const VK_LBUTTON = &H1
    Private Const VK_RBUTTON = &H2

    Private Function watch() As Integer(,)
        Dim pos As PointAPI
        Dim SetPoints(0, 1) As Integer

        If GetAsyncKeyState(VK_RBUTTON) Then
            GetCursorPos(pos)
            SetPoints(0, 0) = pos.x
            SetPoints(0, 1) = pos.y
            Beep()
        End If
        Return SetPoints
    End Function

    Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        Dim DetectMouseClick As Integer(,) = watch()
    End Sub
End Class
Join the community to see this answer!
Join our exclusive community to see this answer & millions of others.
Unlock 1 Answer and 7 Comments.
Join the Community
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 7 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros