How reveive error message?

General discussion for topics related to the FreeBASIC project or its community.
aurelVZAB
Posts: 666
Joined: Jul 02, 2008 14:55
Contact:

How reveive error message?

Post by aurelVZAB »

Hi to all

i am using windows
so is there any example about

HOW TO RECEIVE error message from fbc compiler from
code editor ?

thnx
dodicat
Posts: 7983
Joined: Jan 10, 2006 20:30
Location: Scotland

Re: How reveive error message?

Post by dodicat »

Compile with option -exx.
Use an editor/ide which keeps the console open so you can read the messages.
OR
You can try this
write errload at the beginning of each sub/function
write errhandle at the end
You can do the same in the main module.

Code: Select all


'============ERROR ROUTINE=======================
#cmdline "-exx"

#macro errload
Print "Error handler active."
Dim errnum as long
On Error Goto ehandler
#endmacro

#macro errhandle
Goto skipover
	ehandler:
    Errnum = Err()
    Print "ERROR ";Errnum;"  ";
    Select Case as const Errnum
    case 0: Print " ... "
    Case 1 :Print  "Illegal function call" 
    Case 2 :Print  "File not found signal" 
    Case 3 :Print  "File I/O error" 
    Case 4 :Print  "Out of memory" 
    Case 5 :Print  "Illegal resume" 
    Case 6 :Print "Out of bounds array access" 
    Case 7 :Print  "Null Pointer Access" 
    Case 8 :Print  "No privileges" 
    Case 9 :Print  "interrupted signal" 
    Case 10 :Print  "illegal instruction signal" 
    Case 11 :Print  "floating point error signal" 
    Case 12 :Print  "segmentation violation signal" 
    Case 13 :Print  "Termination request signal" 
    Case 14 :Print  "abnormal termination signal" 
    Case 15 :Print  "quit request signal" 
    Case 16 :Print  "return without gosub" 
    Case 17 :Print  "end of file" 
    End Select
    Print "Function: " &__function__
    #ifdef __FB_LANG__
    #if __FB_LANG__ = "qb"
    Print "Module: " & *__Ermn
    #else
     Print "Module: " & *Ermn
    #endif
    #endif
    Print "Line: " & Erl
    'OPTIONAL BELOW
    'Print "Press a key to exit"
    'Sleep
    'End 
skipover: 
#endmacro

'==================END ERROR ROUTINE====================================


Sub dothis
    errload
    open "nonesuch" for input as #1
    close #1
   errhandle
End Sub

function dothat() as long
    errload
    return 2023
    errhandle
    end function

dothis
print dothat
errload
 Dim As Long Pointer o
    Print *o
errhandle
sleep 
Please note these are run time error messages,
aurelVZAB
Posts: 666
Joined: Jul 02, 2008 14:55
Contact:

Re: How reveive error message?

Post by aurelVZAB »

thanks dodicat

i mean in first place receive message then show it in a editor ...
let say using multi line edit control
caseih
Posts: 2157
Joined: Feb 26, 2007 5:32

Re: How reveive error message?

Post by caseih »

So what you're really asking is how to run a program as a child process and capture it's output (std out and std err)? Like what IDEs do?

I'd check the source code to FBIDE and see how they do it.
aurelVZAB
Posts: 666
Joined: Jul 02, 2008 14:55
Contact:

Re: How reveive error message?

Post by aurelVZAB »

yes caseih that one
i would like to add it into my FB editor
and thanks
SARG
Posts: 1764
Joined: May 27, 2005 7:15
Location: FRANCE

Re: How reveive error message?

Post by SARG »

Try that :

Code: Select all

Const TEST_COMMAND = "<path compiler>.exe <path source><source name>.bas"

Open Pipe TEST_COMMAND For Input As #1

Dim As String ln
Do Until EOF(1)
    Line Input #1, ln
    Print "output=";ln
Loop

Close #1
sleep
aurelVZAB
Posts: 666
Joined: Jul 02, 2008 14:55
Contact:

Re: How reveive error message?

Post by aurelVZAB »

SARG

thanks

but i need something on win API level
SARG
Posts: 1764
Joined: May 27, 2005 7:15
Location: FRANCE

Re: How reveive error message?

Post by SARG »

aurelVZAB wrote: Jan 15, 2023 11:40 but i need something on win API level
I don't understand : the goal is to receive the ouput from the compiler not to use Win API.....
So what is the exact problem with the proposed solution. Under the hood (on Windows) open pipe uses Win API, open pipe with fbc is just an easy way.
aurelVZAB
Posts: 666
Joined: Jul 02, 2008 14:55
Contact:

Re: How reveive error message?

Post by aurelVZAB »

the goal is to use win api
because editor is not written with FB then with o2
SARG
Posts: 1764
Joined: May 27, 2005 7:15
Location: FRANCE

Re: How reveive error message?

Post by SARG »

The easiest way : write a dll using fbc code and use it in your O2 code otherwise look at createpipe and so on in the Win SDK manual.....

Btw you should have say the reason but I guess at first you don't want to talk about O2 ;-)
dodicat
Posts: 7983
Joined: Jan 10, 2006 20:30
Location: Scotland

Re: How reveive error message?

Post by dodicat »

Hi aurelVZAB
I got the wrong end of your question, "error message" threw me, you want compiler messages.
Please pop in your own path to an fb compiler, or any compiler which will output text when it is run (no need to compile any file here, all you need is the compiler raw output to test )
I know nothing about Win SDK or O2, sorry.

Code: Select all

#Include Once "windows.bi"

Declare Function fb_Set_Font (Font As String,Size As Integer,Bold As Integer=0,Italic As Integer=0,Underline As Integer=0,StrikeThru As Integer=0) As HFONT
Declare Function pipeout(s As String) As String

Declare Function main As Long
End main


Dim Shared As zString * 1024 path="C:\Users\Computer\Desktop\fb\FreeBASIC-1.09.0-winlibs-gcc-9.3.0\fbc64.exe"


Function WndProc(hWnd As HWND, msg As UINT, wParam As WPARAM, lParam As LPARAM) As LRESULT
    Static As hwnd ebox,btn
    Select Case msg
    
    Case WM_CREATE
        btn=CreateWindowEx(NULL,"button", "compiler", WS_VISIBLE Or WS_CHILD , 0,20,60,40, hwnd, Cast(Any Ptr,1), NULL, NULL) 
        ebox= CreateWindowEx(NULL,"edit", "", WS_VISIBLE Or WS_CHILD Or WS_VSCROLL Or WS_HSCROLL Or WS_Border Or ES_MULTILINE Or ES_AUTOVSCROLL , 0,350, 750, 200, hwnd,0, NULL, NULL) 
        Dim As HFONT   f1=fb_Set_Font("Courier new",10,,true),f2=fb_Set_Font("times new roman",10,,false)
        SendMessage(ebox,WM_SETFONT,Cast(WPARAM,f1),0)
        SendMessage(btn ,WM_SETFONT,Cast(WPARAM,f2),0)
        
    Case WM_COMMAND
    If Loword(wParam) =1 Then
       var m=pipeout(path)
        setwindowtext(ebox,m)
    End If
    
    
   Case WM_CLOSE
    PostQuitMessage(NULL)
   End Select

Return DefWindowProc(hWnd, msg, wParam, lParam)
End Function

Function MAIN As Long
    ' Create  window class:
    Dim As WNDCLASS wcls
    Function=0
    With wcls
        .style      = CS_HREDRAW Or CS_VREDRAW
        .lpfnWndProc  = @WndProc
        .hInstance    = GetModuleHandle(NULL)
        .hIcon      = LoadIcon(NULL, IDI_APPLICATION)
        .hCursor      = LoadCursor(NULL, IDC_ARROW)
        .hbrBackground  = GetStockObject(WHITE_BRUSH)
        .lpszMenuName  = NULL
        .lpszClassName  = Strptr("WindowClass")
    End With
    
    If RegisterClass(@wcls) = FALSE Then
        MessageBox(NULL, "RegisterClass('WindowClass') FAIL!", "Error!", MB_OK Or MB_ICONERROR)
        End
    End If
    
    'mainwindow
    CreateWindowEx(NULL, "WindowClass", "Some editor", WS_OVERLAPPEDWINDOW Or WS_VISIBLE, 100, 100, 800, 600, NULL, NULL, NULL, NULL)
    
    Dim As MSG uMsg
    While GetMessage(@uMsg, NULL, NULL, NULL) <> FALSE
        TranslateMessage(@uMsg)
        DispatchMessage(@uMsg)
    Wend
End Function

Function fb_Set_Font (Font As String,Size As Integer,Bold As Integer,Italic As Integer,Underline As Integer,StrikeThru As Integer) As HFONT
    Dim As HDC hDC=GetDC(HWND_DESKTOP)
    Dim As Integer CyPixels=GetDeviceCaps(hDC,LOGPIXELSY)
    ReleaseDC(HWND_DESKTOP,hDC)
    Return CreateFont(0-(Size*CyPixels)/72,0,0,0,Bold,Italic,Underline,StrikeThru,ANSI_CHARSET _
    ,OUT_TT_PRECIS,CLIP_DEFAULT_PRECIS,DEFAULT_QUALITY,FF_DONTCARE,Font)
End Function

Function pipeout( s As String) As String
    Var f=Freefile
    Dim As String tmp
    Open Pipe s For Input As #f 
    s=""
    Do Until Eof(f)
        Line Input #f,tmp
        s+=tmp+Chr(13,10)
    Loop
    Close #f
    Return s
End Function 


 
aurelVZAB
Posts: 666
Joined: Jul 02, 2008 14:55
Contact:

Re: How reveive error message?

Post by aurelVZAB »

thanks dodicat

sorry if i ask it in a wrong way...
yes compiler messages ...including of course error messages if user made mistake or error
ok
i will try code .. :)
aurelVZAB
Posts: 666
Joined: Jul 02, 2008 14:55
Contact:

Re: How reveive error message?

Post by aurelVZAB »

dodicat
in my case path is :

Code: Select all

Dim Shared As zString * 1024 path="D:\FreeBASIC-1.09.0-win64\FreeBASIC-1.09.0-win64\fbc.exe"
is that OK?

i compiled code and what i get is console with warning
D:\FreeBASIC-1.09.0-win64\FreeBASIC-1.09.0-win64\CompilerMessanger.bas(50) warning 4(2): Suspicious pointer assignment
Is that OK ?
aurelVZAB
Posts: 666
Joined: Jul 02, 2008 14:55
Contact:

Re: How reveive error message?

Post by aurelVZAB »

@dodicat

can you explain to me why is always this ugly warning in fb:
this wc class member ..name :

Code: Select all

.lpszClassName  = strptr ("WindowClass")
Suspicious pointer assignment
aurelVZAB
Posts: 666
Joined: Jul 02, 2008 14:55
Contact:

Re: How reveive error message?

Post by aurelVZAB »

sorry @dodicat
if i bothering you with this "suspicous pointer"
i figured that must be declared inside FBMain()
now compile properly with output window show compiler messages when i click
button "Compiler "

Code: Select all

Function MAIN As Long

    ' Create  window class:
	dim WND_CLASS_NAME  as string 
    WND_CLASS_NAME ="WindowClass"
    Dim As WNDCLASS wcls
    Function=0
    With wcls
        .style      = CS_HREDRAW Or CS_VREDRAW
        .lpfnWndProc  = @WndProc
        .hInstance    = GetModuleHandle(NULL)
        .hIcon      = LoadIcon(NULL, IDI_APPLICATION)
        .hCursor      = LoadCursor(NULL, IDC_ARROW)
        .hbrBackground  = GetStockObject(WHITE_BRUSH)
        .lpszMenuName  = NULL
        '.lpszClassName  = strptr ("WindowClass")
		.lpszClassName = strptr (WND_CLASS_NAME)
    End With 
thanks a lot ..ahh i am not used very much on FB tricks ...shame on me
Post Reply