By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,528 Members | 1,345 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,528 IT Pros & Developers. It's quick & easy.

GetKeyState

P: n/a
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
Share this Question
Share on Google+
5 Replies


P: n/a
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

P: n/a
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

P: n/a
"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

P: n/a
"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

P: n/a
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 discussion thread is closed

Replies have been disabled for this discussion.