This has been driving me nuts for a couple of days now, and I've finally tracked down what's wrong with all my WinAPI code, though I have zero idea why or how to fix it.
I've cut this down to the absolute minimum amount of code required to show the error.
The code
The PSApi Module it requires. ( I Called it glimmer.psapi, so you'll need to match it or change the import call if you're going to test this.
Now run it and you'll see that, despite being set to 0 and never being changed, hp is a huge number right after EnumProcesses() is called. Moreover, it changes every time I call debuglog. Now maybe I've gone a bit batchy after two days straight of putzing around with this, but I'm thinking variables shouldn't be randomly changing every time I call debuglog.
Note that I've made the array much bigger than it needs to be to ensure that the API is not overwriting my variables. It doesn't get close to the end of the array anyway.
I've cut this down to the absolute minimum amount of code required to show the error.
The code
SuperStrict Import glimmer.psapi Function Enumerate() Local ProcessIDs:Int[]=New Int[1000] Local cb:Int Local cbNeeded:Int Local lret:Int Local NumProcessesFound:Int Local Counter:Int 'Local hProcess:Int Local hp:Int=0 cb=100 cbNeeded=0 DebugLog hp lret=EnumProcesses(Varptr(ProcessIDs[0]),cb,Varptr(cbNeeded)) DebugLog hp DebugLog hp DebugLog hp End Function Enumerate()
The PSApi Module it requires. ( I Called it glimmer.psapi, so you'll need to match it or change the import call if you're going to test this.
SuperStrict Module Glimmer.PSApi ModuleInfo "Version 1.00" Import "-lpsapi" Extern Function EnumProcesses(pProcessIDs:Byte Ptr,cb:Int,cbNeeded:Int Ptr) = "EnumProcesses@12" End Extern
Now run it and you'll see that, despite being set to 0 and never being changed, hp is a huge number right after EnumProcesses() is called. Moreover, it changes every time I call debuglog. Now maybe I've gone a bit batchy after two days straight of putzing around with this, but I'm thinking variables shouldn't be randomly changing every time I call debuglog.
Note that I've made the array much bigger than it needs to be to ensure that the API is not overwriting my variables. It doesn't get close to the end of the array anyway.