Click here to Skip to main content
15,887,485 members
Please Sign up or sign in to vote.
2.00/5 (1 vote)
See more:
Public Declare Function KeyState Lib "user32" (ByVal vkey As Long) As Integer

I m getting a PInvoke error in Keystate Function in visual studio 2010.

how can it be solved.
It works on VS2008 but not in VS2010
help me


thanks in advance...

I get this error when using GetAsyncKeyState........

"A call to PInvoke function 'KeyFrmApp!keyFrmApp.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."
Posted
Updated 5-Mar-12 19:49pm
v2
Comments
Sergey Alexandrovich Kryukov 5-Mar-12 2:19am    
It can be solved if you show appropriate code fragment, including all attribute and usage of the P/Invoked code.

Please understand: our access to your hard drive is somewhat limited due to winter conditions. :-)
--SA
TNJS82 5-Mar-12 2:30am    
When I call that function like keystate(i) it show the error...
if I change the name of function to "keew" or "gssa" it show the error that
EntryPointNotFound exception
Unable to find an entry point named 'Keew' in DLL 'user32'.
:-(
Sergey Alexandrovich Kryukov 5-Mar-12 12:42pm    
Well, then why are you not providing comprehensive information? "Improve question" is above.
--SA
TNJS82 5-Mar-12 2:29am    
When I call that function like keystate(i) it show the error...
if I change the name of function to "keew" or "gssa" it show the error that
EntryPointNotFound exception
Unable to find an entry point named 'Keew' in DLL 'user32'.

There is no function (as far as I know, and PInvoke.net agrees) called "KeyState" in user32.dll

This could be your problem...

Check what you are trying to do, and see if you are meant to call GetKeyState, or GetAsyncKeyState, or some other function or module altogether.
 
Share this answer
 
It seems that you want to call GetAsyncKeyState function from User32.dll.. Check
the below code, I think this may help you.

Public Declare Function GetAsyncKeyState Lib "user32.dll" (ByVal vKey As Int32) As UShort

Usage:

Public Shared ReadOnly Property KeyStatus(ByVal Key As Keys) As Boolean
    Get
        If Key = Keys.LButton AndAlso My.Computer.Mouse.ButtonsSwapped Then
            Key = Keys.RButton
        ElseIf Key = Keys.RButton AndAlso My.Computer.Mouse.ButtonsSwapped Then
           Key = Keys.LButton
        End If
        Return API.Devices.GetAsyncKeyState(Key) And &H8000US
    End Get
End Property


Above code provide the status of the key and mouse button.
 
Share this answer
 
the Error was Due to the Mismatched Datatype in My code.....
thanks....OriginalGriff & ChandraKantt.....

"Keystate" is not A function in user32.dll it is "GetAsyncKeyState"....
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900