Author Topic: #console ?  (Read 2223 times)

0 Members and 1 Guest are viewing this topic.


  • Full Member
  • ***
  • Posts: 181
#console ?
« on: October 15, 2010, 05:38:41 AM »
  This demo shows "process detach" when using #console.
Comment '#console and uncomment the AllocConsole,FreeConsole and this msg does not appear in the console.
Not sure if it's left over debugging or I am doing something wrong?


Code: [Select]


  library "KERNEL32.DLL"
  declare FUNCTION AllocConsole    ALIAS "AllocConsole" () AS LONG
  declare FUNCTION FreeConsole     ALIAS "FreeConsole"() AS LONG
  declare FUNCTION GetCommandLine  ALIAS "GetCommandLineA" () AS DWORD
  declare FUNCTION GetStdHandle    ALIAS "GetStdHandle" (BYVAL handle AS DWORD) AS DWORD
  declare FUNCTION WriteConsole    ALIAS "WriteConsoleA" (BYVAL hConsoleOutput AS DWORD, lpBuffer AS ASCIIZ, BYVAL nNumberOfCharsToWrite AS LONG, lpNumberOfCharsWritten AS LONG, BYVAL lpReserved AS LONG) AS LONG
  declare FUNCTION ReadConsole     ALIAS "ReadConsoleA" (BYVAL hConsoleInput AS DWORD, BYVAL lpBuffer AS DWORD, BYVAL nNumberOfCharsToRead AS LONG, lpNumberOfCharsRead AS LONG, pInputControl AS ANY) AS LONG
  declare FUNCTION SetConsoleTitle ALIAS "SetConsoleTitleA" (lpConsoleTitle AS ASCIIZ) AS LONG
  library ""

  dim as string bufin
  dim as long buflen,bufrit

  dim as string tab,cr,qu
  tab=chr 9
  qu=chr 34

  bufin=nuls 1000

  function cprint(bufout as string)
      Dim As long ConsOut
      ConsOut = GetStdHandle (%STD_OUTPUT_HANDLE)
    buflen=len bufout
    WriteConsole ConsOut,bufout,buflen,bufrit,0
  end function

  function cinput(s as string) as string
    cprint s
    ConsIn =GetStdHandle (%STD_INPUT_HANDLE)
    ReadConsole ConsIn,*bufin,100,bufrit,0
    function=left bufin,bufrit
  end function

  function commandline() as string
    dim byref z as zstring 
  end function

  function stripquotes(s as string) as string
    dim as long a
    if a=34 then
      a=instr 2,s,qu
      s=mid s,2,a-2
    end if
  end function

Function O2Main() As sys 
    dim s as string
    dim i as integer
    SetConsoleTitle "Test Oxygen Console"
    for i = 1 to 5
        cprint("This is string "+str(i)+ cr)
    next i
    s = cinput("press enter key")
    Function = 1
End Function


Charles Pegge

  • Admin Support Member
  • *****
  • Posts: 4205
    • Oxygen Basic
Re: #console ?
« Reply #1 on: October 15, 2010, 09:16:05 AM »

Yes James, that is indeed a swab left inside the patient

This is the offending code.
FreeBasic 0.21.1
Code: [Select]
sub dtor() destructor
    print "process detach"
end sub

Thanks for reporting it!