Author Topic: #console ?  (Read 3139 times)

0 Members and 1 Guest are viewing this topic.

jcfuller

  • Guest
#console ?
« on: October 15, 2010, 05:38:41 AM »
Charles,
  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?


James

Code: [Select]

#console
#basic

  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 ""


  %STD_INPUT_HANDLE  = -10
  %STD_OUTPUT_HANDLE = -11
  %STD_ERROR_HANDLE  = -12
 
  dim as string bufin
  dim as long buflen,bufrit

  dim as string tab,cr,qu
  tab=chr 9
  qu=chr 34
  cr=chr(13)+chr(10)

  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 
    &z=GetCommandLine
    function=z
  end function

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

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

O2Main()   



Charles Pegge

  • Guest
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!
Charles