GetCursorPos - PInvoke error!!

  • Thread starter Thread starter Rajesh Soni
  • Start date Start date
R

Rajesh Soni

Hi!

I'm getting a PInvoke error while trying to execute the following code...


declaration:
Structure POINTAPI

Dim x As IntPtr

Dim y As IntPtr

End Structure

Private Declare Sub GetCursorPos Lib "User32" (ByVal lpPoint As POINTAPI)


usage:
Dim MouseLocation As New POINTAPI

GetCursorPos(MouseLocation)



Please help!



Thanks in advance,

Rajesh
 
Hi!

I'm getting a PInvoke error while trying to execute the following code...

declaration:
Structure POINTAPI

Dim x As IntPtr

Dim y As IntPtr

End Structure

Private Declare Sub GetCursorPos Lib "User32" (ByVal lpPoint As POINTAPI)

usage:
Dim MouseLocation As New POINTAPI

GetCursorPos(MouseLocation)

Please help!

Thanks in advance,

Rajesh

Structure PointAPI
Public x As Integer ' Int32 if you prefer
Publci y As Integer ' Int32 if you prefer
End Structure

Public Declare Function GetCursorPos Lib user(ByRef lpPoint As
PointAPI) As Boolean
 
Structure PointAPI
Public x As Integer ' Int32 if you prefer
Publci y As Integer ' Int32 if you prefer
End Structure

Public Declare Function GetCursorPos Lib user(ByRef lpPoint As
PointAPI) As Boolean

woops - hit send to soon...
Public Declare Function GetCursorPos Lib "user32" (ByRef lpPoint As
PointAPI) As Boolean
 
Tom,

Thanks Tom, but unfortunately i'm getting the same error :(

A call to PInvoke function 'Form_Name_.Form1::GetCursorPos' 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.

- Rajesh
 
Rajesh Soni said:
Private Declare Sub GetCursorPos Lib "User32" (ByVal lpPoint As POINTAPI)

In addition to the other replies: Why not use 'Cursor.Position'?
 
Tom,

Thanks Tom, but unfortunately i'm getting the same error :(

A call to PInvoke function 'Form_Name_.Form1::GetCursorPos' 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.

- Rajesh






- Show quoted text -

post your code. You have not declared the function correctly.
 
Tom,

Thanks Tom, but unfortunately i'm getting the same error :(

working code:

Option Explicit On
Option Strict On
Imports System.Runtime.InteropServices


Public Class Form1
Private Structure PointAPI
Public x As Integer
Public y As Integer
End Structure

Private Declare Function GetCursorPos Lib "user32" (ByRef lpPoint
As PointAPI) As Boolean

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e
As System.EventArgs) Handles Button1.Click
Dim pt As PointAPI
If GetCursorPos(pt) Then
MessageBox.Show(String.Format("x={0}, y={1}", pt.x, pt.y))
End If
End Sub
End Class
 
Tom,

Thanks a ton!!!!

-Rajesh

Tom Shelton said:
working code:

Option Explicit On
Option Strict On
Imports System.Runtime.InteropServices


Public Class Form1
Private Structure PointAPI
Public x As Integer
Public y As Integer
End Structure

Private Declare Function GetCursorPos Lib "user32" (ByRef lpPoint
As PointAPI) As Boolean

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e
As System.EventArgs) Handles Button1.Click
Dim pt As PointAPI
If GetCursorPos(pt) Then
MessageBox.Show(String.Format("x={0}, y={1}", pt.x, pt.y))
End If
End Sub
End Class
 
Back
Top