Qbasicnews.com

Full Version: FreeBASIC Bug? (Win32 API (kernel32) GetConsoleProcessList)
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Greetings,
No matter how I try and work this, it continues to drop an "Unknown Error"...

Code:
Declare Function GetConsoleProcessList Lib "kernel32" (lpdwProcessList As Long, ByVal dwProcessCount As Long) As Long

Dim Ret           As Long

'Create a buffer of Longs
ReDim ProcessList(0 To 9) As Long
'Get the list of process IDs associated with this console
Ret = GetConsoleProcessList(ProcessList(0), 10)
'If the buffer was not large enough...
If Ret > 9 Then
   '...create a larger buffer
   ReDim ProcessList(0 To Ret - 1) As Long
   ' and retry
   Ret = GetConsoleProcessList(ProcessList(0), Ret + 1)
End If

Sleep

Any remarks?
Don't you have to include the lib or seomthing >_> I don't know...
whitetiger: hence the Lib part of the declaration. Tongue

I've never used this function before so I have no idea how it works. However, it appears that this function only works in Windows XP or higher, and it appears to use DWORDs, which I do believe are 64 bit values, so you might want to use the INT64 UDT and see if you get different results. INT64 is included in the latest winbase.bi. But if that's not the case, then observe the first argument: it's a pointer, so maybe you need to be passing a pointer the function? Smile
Nope, it's not Int64...

The above code I posted was one of my last attempts to get it to work, and was a modified VB6 example. The VB version works perfectly, howeve FB drops "Unknown Error".

http://msdn.microsoft.com/library/defaul...sslist.asp

If anyone wants to see it in VB (Hex! Curse! I know, I said the "V" word Big Grin ) I'll post the complete (original) VB example.

As far as a pointer, yes, it is a pointer and I've tried utilizing that fact. Everything I tried still gave the "Unknown Error" pointer or not.

Don't be scared, TRY IT.... Smile
GetConsoleProcessList is not included in kernel32's import library, as it was added only for XP. This code worked tho:

Code:
'$include: 'win\kernel32.bi'

dim GetConsoleProcessList as function (lpdwProcessList As Long, ByVal dwProcessCount As Long) As Long

    dim hlib as integer
    hlib = LoadLibrary( "kernel32.dll" )
    GetConsoleProcessList = GetProcAddress( hlib, "GetConsoleProcessList" )

Dim Ret           As Long

ReDim ProcessList(0 To 9) As Long
Ret = GetConsoleProcessList(ProcessList(0), 10)
If Ret > 9 Then
   ReDim ProcessList(0 To Ret - 1) As Long
   Ret = GetConsoleProcessList(ProcessList(0), Ret + 1)
End If

for i = 0 to ret-1
    print ProcessList(i)
next i

Sleep
Aht.... Lookie there.
I've been blessed with a fix from the FB God. lol

Thanks man!
OK I was kinda right >_>
Hey v1c,
Try GetConsoleProcessList in a sub or function and see what happens now. Wink

Code:
' Originally written by Andre Victor

'$include: 'win\kernel32.bi'

Declare Sub Test()
dim GetConsoleProcessList as function (lpdwProcessList As Long, ByVal dwProcessCount As Long) As Long

   dim hlib as integer
   hlib = LoadLibrary( "kernel32.dll" )
   GetConsoleProcessList = GetProcAddress( hlib, "GetConsoleProcessList" )
  
Dim Ret           As Long

ReDim ProcessList(0 To 9) As Long
Ret = GetConsoleProcessList(ProcessList(0), 10)
If Ret > 9 Then
   ReDim ProcessList(0 To Ret - 1) As Long
   Ret = GetConsoleProcessList(ProcessList(0), Ret + 1)
End If

for i = 0 to ret-1
   print ProcessList(i)
next i

Sleep


Sub Test()
   ReDim ProcessList(0 To 9) As Long
   Ret = GetConsoleProcessList(ProcessList(0), 10)
   If Ret > 9 Then
      ReDim ProcessList(0 To Ret - 1) As Long
      Ret = GetConsoleProcessList(ProcessList(0), Ret + 1)
   End If
End Sub

..\unknownerror.bas(30): error 40: Expected 'END SUB' or 'END FUNCTION', found: '(' On Line: 30
Sure, it must be declared as shared or the var GetConsoleProcessList will be magically declared as an integer inside the proc, so ()'s aren't allowed, as it's not a function or array - or a function pointer.
heh,
I figured it was something stupid on my end (common). It makes perfect sence, thanks.