473,396 Members | 1,805 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

GetKeyState

ats
Hi there,

I have the following Function and Const declarations in my project:

Public Declare Function GetKeyState Lib "USER32" Alias "GetKeyState" (ByVal
nVirtKey As Long) As Integer

Public Const VK_SHIFT As Integer = 16

I then have the following code:

Dim k as Integer

k = GetKeyState(VK_SHIFT)

As soon the code hits the last line above I get the following error:

"PInvokeStackImbalance was detected
Message: A call to PInvoke function
'LLWinDotNet!LLWinDotNet.mGlobals::GetKeyState' 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."

Can anybody help me with this please.

TIA

--
ats@jbex

They say they've got control of you
But that's not true you know
They say they're a part of you
And that's a lie you know
They say you will never be
Free free free

SLF - Alternative Ulster
Oct 26 '07 #1
5 9612
ats@jbex wrote:
Public Declare Function GetKeyState Lib "USER32" Alias "GetKeyState" (ByVal
nVirtKey As Long) As Integer
Public Const VK_SHIFT As Integer = 16
I'm no expert but it strikes me that we don't tend to use Long's with
API calls very much these days. Our "new-and-improved", 32-bit Integer
takes care of that now.

Did you lift this declaration from VB "Proper"? If so, you need to
change the data types:

Declare Function GetKeyState Lib "USER32" Alias "GetKeyState" _
( ByVal nVirtKey As Integer ) As Short

Public Const VK_SHIFT As Short = 16

HTH,
Phill W.
Oct 26 '07 #2
ats
On Fri, 26 Oct 2007 11:13:54 +0100, Phill W. wrote:
ats@jbex wrote:
>Public Declare Function GetKeyState Lib "USER32" Alias "GetKeyState" (ByVal
nVirtKey As Long) As Integer
Public Const VK_SHIFT As Integer = 16

I'm no expert but it strikes me that we don't tend to use Long's with
API calls very much these days. Our "new-and-improved", 32-bit Integer
takes care of that now.

Did you lift this declaration from VB "Proper"? If so, you need to
change the data types:

Declare Function GetKeyState Lib "USER32" Alias "GetKeyState" _
( ByVal nVirtKey As Integer ) As Short

Public Const VK_SHIFT As Short = 16

HTH,
Phill W.
Fantatsic. Tht worked. I knew about changing teh Long's to Integers but
didn't spot the one nesting inside the Function statement :-)

--
ats@jbex

I'm not gonna be taken in
They said if I don't join I just can't win
I've heard that story many times before
And every time I threw it out the door

SLF - Wasted Life
Oct 26 '07 #3
"ats@jbex" <al***@allenjones.NOSPAM.co.PLEASE.ukschrieb
Hi there,

I have the following Function and Const declarations in my project:

Public Declare Function GetKeyState Lib "USER32" Alias "GetKeyState"
(ByVal nVirtKey As Long) As Integer

Public Const VK_SHIFT As Integer = 16
These are old declarations for VB6 and below.
Have a look at http://www.pinvoke.net/ (browse on the left side)
Armin
Oct 26 '07 #4
"Phill W." <p-.-a-.-w-a-r-d-@-o-p-e-n-.-a-c-.-u-kschrieb
ats@jbex wrote:
Public Declare Function GetKeyState Lib "USER32" Alias
"GetKeyState" (ByVal nVirtKey As Long) As Integer
Public Const VK_SHIFT As Integer = 16

I'm no expert but it strikes me that we don't tend to use Long's
with API calls very much these days. Our "new-and-improved", 32-bit
Integer takes care of that now.
Sorry, you were faster. :-) (I received your message after I sent mine)
Armin

Oct 26 '07 #5
Armin Zingler wrote:
"Phill W." <p-.-a-.-w-a-r-d-@-o-p-e-n-.-a-c-.-u-kschrieb
>ats@jbex wrote:
Public Declare Function GetKeyState Lib "USER32" Alias
"GetKeyState" (ByVal nVirtKey As Long) As Integer
Public Const VK_SHIFT As Integer = 16

I'm no expert but it strikes me that we don't tend to use Long's
with API calls very much these days. Our "new-and-improved", 32-bit
Integer takes care of that now.

Sorry, you were faster. :-) (I received your message after I sent mine)
No apology necessary ...

so long as we both came up with the /same/ answer. ;-)

Nice link, BTW; I've bookmarked it ready for next time.

Regards,
Phill W.
Oct 26 '07 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: Rune | last post by:
Hey I'm trying to build a gui application and need to know if the user is actually holding down the shift or ctrl key. That is, if the user currently is holding down the shift key. In pseudo...
5
by: Markus Wildgruber | last post by:
Hi! Is there a substitute in the .NET Framework for the GetKeyState(...) function? I want to check whether the shift key is pressed. What's the best way to do this? Do I have to use...
4
by: melanieab | last post by:
Hi, I need to check and see if a Tab key was pressed. I found GetKeyState() but that only seems to be for Visual Basic. Is there anything like it for c#? (GetKeyName didn't seem too promising...
0
by: Ramiro Blanco | last post by:
I am using a C++ source code generator from Computer Associates, called Allfusion Plex, and need to insert source code to set focus on the next editable cell in a grid. For example, I have a...
2
by: Chris | last post by:
can anyone out there tell me how do u check the state of these keys in vb.net? or is there any components in the .NET Framework that supports doing so? any help is appreciated. Thanks.
4
by: active | last post by:
I can use Control.ModifierKeys to determine if a modifying key is pressed when executing MouseDown event, but how can I determine if an "M" was pressed?? Possible? Can't find a clue in...
10
by: lgbjr | last post by:
Hi All, In VB.Net how do I determine if CapsLock is on/off (same for NumLock) and whether the input mode is set to Insert or Overwrite (Insert Key). I just added a status bar to my app, and I...
3
by: Me | last post by:
Trying to get the current status of the insert key. Found my.computer.keyboard.capslock, but no such item for insert key. Anyone have some code to help. Can't figure out getkeystate. compiler...
5
by: jpenguin | last post by:
i am altering some Win32 C++ code. The code is for ASCII Pac-man. I need a replacement for GetKeyState() because it used windows.h. Can I use the windowsx.h included with my WINE? Orr it would be...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.