GetKeyState

A

ats@jbex

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
 
P

Phill W.

ats@jbex said:
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.
 
A

ats@jbex

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
 
A

Armin Zingler

ats@jbex said:
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
 
A

Armin Zingler

Phill W. said:
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
 
P

Phill W.

Armin said:
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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Top