Visual Studio 2010 PInvoke错误

Visual Studio 2010 PInvoke错误

问题描述:

公共声明函数KeyState库"user32"(ByVal vkey只要长)作为整数

我在Visual Studio 2010的键状态函数中收到PInvoke错误.

如何解决.
它适用于VS2008,但不适用于VS2010
帮帮我


在此先感谢...

使用GetAsyncKeyState时出现此错误.
对PInvoke函数``KeyFrmApp!keyFrmApp.Form1 :: GetAsyncKeyState的调用"使堆栈不平衡.这很可能是因为托管PInvoke签名与非托管目标签名不匹配.请检查PInvoke签名的调用约定和参数.匹配目标非托管签名."

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

user32.dll中没有名为"KeyState"的功能(据我所知,PInvoke.net同意)

这可能是您的问题...

检查您要尝试执行的操作,并查看您是否打算完全调用GetKeyState或GetAsyncKeyState或某些其他函数或模块.
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.


似乎您想从以下位置调用GetAsyncKeyState函数User32.dll ..检查
以下代码,我认为这可能对您有所帮助.

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.


该错误是由于我的代码中的数据类型不匹配所致.....
谢谢....原始Griff& ChandraKantt .....

"keystate"不是user32.dll中的函数,而是"GetAsyncKeyState"....
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"....