GetCursorPos - PInvoke error!!

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Rajesh Soni

    GetCursorPos - PInvoke error!!

    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(Mo useLocation)



    Please help!



    Thanks in advance,

    Rajesh



  • Tom Shelton

    #2
    Re: GetCursorPos - PInvoke error!!

    On Feb 6, 1:57 pm, "Rajesh Soni" <rajeshgs...@ya hoo.comwrote:
    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(Mo useLocation)
    >
    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

    --
    Tom Shelton

    Comment

    • Tom Shelton

      #3
      Re: GetCursorPos - PInvoke error!!

      On Feb 10, 2:31 pm, "Tom Shelton" <tom_shel...@co mcast.netwrote:
      On Feb 6, 1:57 pm, "Rajesh Soni" <rajeshgs...@ya hoo.comwrote:
      >
      >
      >
      >
      >
      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(Mo useLocation)
      >
      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
      >
      woops - hit send to soon...
      Public Declare Function GetCursorPos Lib "user32" (ByRef lpPoint As
      PointAPI) As Boolean

      --
      Tom Shelton

      Comment

      • Rajesh Soni

        #4
        Re: GetCursorPos - PInvoke error!!

        Tom,

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

        A call to PInvoke function 'Form_Name_.For m1::GetCursorPo s' 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

        "Tom Shelton" <tom_shelton@co mcast.netwrote in message
        news:1171143182 .122524.161450@ m58g2000cwm.goo glegroups.com.. .
        On Feb 10, 2:31 pm, "Tom Shelton" <tom_shel...@co mcast.netwrote:
        >On Feb 6, 1:57 pm, "Rajesh Soni" <rajeshgs...@ya hoo.comwrote:
        >>
        >>
        >>
        >>
        >>
        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(Mo useLocation)
        >>
        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
        >>
        >
        woops - hit send to soon...
        Public Declare Function GetCursorPos Lib "user32" (ByRef lpPoint As
        PointAPI) As Boolean
        >
        --
        Tom Shelton
        >


        Comment

        • Herfried K. Wagner [MVP]

          #5
          Re: GetCursorPos - PInvoke error!!

          "Rajesh Soni" <rajeshgsoni@ya hoo.comschrieb:
          Private Declare Sub GetCursorPos Lib "User32" (ByVal lpPoint As POINTAPI)
          In addition to the other replies: Why not use 'Cursor.Positio n'?

          --
          M S Herfried K. Wagner
          M V P <URL:http://dotnet.mvps.org/>
          V B <URL:http://dotnet.mvps.org/dotnet/faqs/>

          Comment

          • Tom Shelton

            #6
            Re: GetCursorPos - PInvoke error!!

            On Feb 10, 2:43 pm, "Rajesh Soni" <rajeshgs...@ya hoo.comwrote:
            Tom,
            >
            Thanks Tom, but unfortunately i'm getting the same error :(
            >
            A call to PInvoke function 'Form_Name_.For m1::GetCursorPo s' 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
            >
            "Tom Shelton" <tom_shel...@co mcast.netwrote in message
            >
            news:1171143182 .122524.161450@ m58g2000cwm.goo glegroups.com.. .
            >
            >
            >
            On Feb 10, 2:31 pm, "Tom Shelton" <tom_shel...@co mcast.netwrote:
            On Feb 6, 1:57 pm, "Rajesh Soni" <rajeshgs...@ya hoo.comwrote:
            >
            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(Mo useLocation)
            >
            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
            >
            woops - hit send to soon...
            Public Declare Function GetCursorPos Lib "user32" (ByRef lpPoint As
            PointAPI) As Boolean
            >
            --
            Tom Shelton- Hide quoted text -
            >
            - Show quoted text -
            post your code. You have not declared the function correctly.

            Comment

            • Rajesh Soni

              #7
              Re: GetCursorPos - PInvoke error!!

              Hey Herfried!

              Thanks for that, it WORKED!!

              -Rajesh


              "Herfried K. Wagner [MVP]" <hirf-spam-me-here@gmx.atwrot e in message
              news:%23v$aPyVT HHA.5016@TK2MSF TNGP05.phx.gbl. ..
              "Rajesh Soni" <rajeshgsoni@ya hoo.comschrieb:
              >Private Declare Sub GetCursorPos Lib "User32" (ByVal lpPoint As POINTAPI)
              >
              In addition to the other replies: Why not use 'Cursor.Positio n'?
              >
              --
              M S Herfried K. Wagner
              M V P <URL:http://dotnet.mvps.org/>
              V B <URL:http://dotnet.mvps.org/dotnet/faqs/>


              Comment

              • Tom Shelton

                #8
                Re: GetCursorPos - PInvoke error!!

                On Feb 10, 2:43 pm, "Rajesh Soni" <rajeshgs...@ya hoo.comwrote:
                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(B yVal sender As System.Object, ByVal e
                As System.EventArg s) 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 Shelton

                Comment

                • Rajesh Soni

                  #9
                  Re: GetCursorPos - PInvoke error!!

                  Tom,

                  Thanks a ton!!!!

                  -Rajesh

                  "Tom Shelton" <tom_shelton@co mcast.netwrote in message
                  news:1171144642 .015936.205720@ m58g2000cwm.goo glegroups.com.. .
                  On Feb 10, 2:43 pm, "Rajesh Soni" <rajeshgs...@ya hoo.comwrote:
                  >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(B yVal sender As System.Object, ByVal e
                  As System.EventArg s) 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 Shelton
                  >

                  Comment

                  Working...