PInvokeStackImbalance when Openprocess
PInvokeStackImbalance when Openprocess
(OP)
I always get the error PInvokeStackImbalance when im trying to call OpenProcess in my VB 2005 application
I have declared Openprocess as following:
Private Declare Function OpenProcess lib "kernel32.dll" (ByVal dwDesiredAccess as long, ByVal bInheritHandle as boolean, ByVal dwProcessId as long) as long
Im using it in this way:
(ExitPid is a "long" return value from the Shell function earlier in the program)
dim hh as long
hh = OpenProcess(1, false, ExitPid)
TerminateProcess(hh, 0)
CloseHandle(hh)
I have declared Openprocess as following:
Private Declare Function OpenProcess lib "kernel32.dll" (ByVal dwDesiredAccess as long, ByVal bInheritHandle as boolean, ByVal dwProcessId as long) as long
Im using it in this way:
(ExitPid is a "long" return value from the Shell function earlier in the program)
dim hh as long
hh = OpenProcess(1, false, ExitPid)
TerminateProcess(hh, 0)
CloseHandle(hh)
RE: PInvokeStackImbalance when Openprocess
API longs are 32 bit, .NET longs are 64 bit, this will create problems on the stack. Maybe you've got things mixed up somewhere....
Greetings,
Rick
RE: PInvokeStackImbalance when Openprocess
RE: PInvokeStackImbalance when Openprocess
CODE
I would think that the long API and the long .NET would be resolved by VB.
HyperEngineer
If it ain't broke, it probably needs improvement.
RE: PInvokeStackImbalance when Openprocess
But if that was the wrong, the function would only return a zero value (function failed), not crash application and return the error PInvokeStackImbalance.
RE: PInvokeStackImbalance when Openprocess
So what happens: You declare your OpenProcess() as receiving parameters of type long. .NET will use 64 bits for those parameters and the windows library expects them to be 32 bits; hence your stack gets corrupted there, hence the error....
Change your declares from long to [b]integer/b] and see if this works.
Greetings,
Rick
RE: PInvokeStackImbalance when Openprocess
Chip H.
____________________________________________________________________ tp://s1.am azon.com/p aypage/PEL YGQVJ8Q7IB /103-68212 58-5919825
Donate to Katrina relief:
ht
If you want to get the best response to a question, please read FAQ222-2244 first