How to use WinMain with FreeBASIC?
Re: How to use WinMain with FreeBASIC?
Try searching the forum for "hinstance" and you get over a thousand results!
Re: How to use WinMain with FreeBASIC?
What kind of syntax is this?
Code: Select all
declare function WinMain ( byval hInstance as HINSTANCE, _
byval hPrevInstance as HINSTANCE, _
byval szCmdLine as zstring ptr, _
byval iCmdShow as integer ) as integer
end WinMain( GetModuleHandle( null ), null, Command( ), SW_NORMAL )
This language has never stop making me surprise!
Isn't the correct syntax of a function is this?
Code: Select all
declare function WinMain ( byval hInstance as HINSTANCE, _
byval hPrevInstance as HINSTANCE, _
byval szCmdLine as zstring ptr, _
byval iCmdShow as integer ) as integer
end function
Code: Select all
WinMain( GetModuleHandle( null ), null, Command( ), SW_NORMAL )
Re: How to use WinMain with FreeBASIC?
In FreeBasic (just like in C/C++) you have to declare a function, because the compiler is a single-pass one and doesn't look ahead for potential methods following later in the code. And that's exactly what the example code does first.
What is does next is calling the END method with the return value of WinMain as argument. Maybe first assigning the result to a temporary variable makes it clearer:
What's missing in your excerpt of the sample code is the actual definition of the WinMain function (done with FUNCTION ... END FUNCTION).
Some reading for declaration vs. definition (everything C/C++, but it's exactly the same principle as in FreeBasic, just a little bit different syntax):
https://stackoverflow.com/questions/141 ... eclaration
https://docs.microsoft.com/en-us/cpp/cp ... itions-cpp
What is does next is calling the END method with the return value of WinMain as argument. Maybe first assigning the result to a temporary variable makes it clearer:
Code: Select all
dim exitCode as integer
exitCode = WinMain( GetModuleHandle( null ), null, Command( ), SW_NORMAL )
end exitCode
Some reading for declaration vs. definition (everything C/C++, but it's exactly the same principle as in FreeBasic, just a little bit different syntax):
https://stackoverflow.com/questions/141 ... eclaration
https://docs.microsoft.com/en-us/cpp/cp ... itions-cpp
Re: How to use WinMain with FreeBASIC?
Well, the End used here is a function:
https://www.freebasic.net/wiki/KeyPgEnd
The End used to end a block of code is another End:
https://www.freebasic.net/wiki/KeyPgEndblock
The former End is just like Free Pascal's Exit:
https://www.freepascal.org/docs-html/rt ... /exit.html
https://www.freebasic.net/wiki/KeyPgEnd
The End used to end a block of code is another End:
https://www.freebasic.net/wiki/KeyPgEndblock
The former End is just like Free Pascal's Exit:
https://www.freepascal.org/docs-html/rt ... /exit.html
-
- Posts: 862
- Joined: May 05, 2015 5:35
- Location: Germany
Re: How to use WinMain with FreeBASIC?
Do you really consider this hint helpful?
@ operator+
In FB it's quite simple:
Code: Select all
#Include "windows.bi"
MessageBoxW(NULL, "First Program", "First", MB_OK)
Re: How to use WinMain with FreeBASIC?
For those who want to be spoon fed, yes (not my word but his).
Re: How to use WinMain with FreeBASIC?
Can you get your head round this miilvyxg?miilvyxg wrote: ↑Feb 19, 2022 13:42 Well, the End used here is a function:
https://www.freebasic.net/wiki/KeyPgEnd
The End used to end a block of code is another End:
https://www.freebasic.net/wiki/KeyPgEndblock
The former End is just like Free Pascal's Exit:
https://www.freepascal.org/docs-html/rt ... /exit.html
Clue: end, like pascal exit ends the program, but with a twist.
Code: Select all
declare function msgbox lib "user32.dll" alias "MessageBoxTimeoutA"(as any ptr,as zstring,as zstring,as long,as long,as long) as long
declare function winmain() as long
end winmain
function winmain() as long
print __function__+" is called"
return 0
end function
sub delayabit destructor
msgbox(0,"Wait 10 seconds or click OK",__function__,0,0,10000)
end sub
Re: How to use WinMain with FreeBASIC?
No. The only thing I see is stupid languages trying to wrap around C/C++ concept of the main function as the program's entry point via hackish and absurb syntax. Return like C/C++ is enough. Why have to invent neither Exit nor End?
Re: How to use WinMain with FreeBASIC?
you can
end 0
or
end 1
or
end 100
or
end function
where function returns a number
you cannot
end sub
because a sub doesn't return anything.
so main or winmain is always a function if you end main or end winmain.
You don't have to end anything in any program, but the windows examples tend to use end winmain, so that is how it comes about.
If you tag destructor after a sub then that sub will run after the end command is deployed.
It is not hackish and absurd syntax, but useable freebasic syntax.
exit can be used in fb to get out of a sub or function or loop early.
exit in pascal is similar to return in fb inside a function, exit(0), return 0
return is c like, but there are three ways to return in fb.
function dothis as long
return 1
function=1
dothis=1
end function
The fb compiler has several interfaces
#lang "qb"
#lang "fblite"
#lang "fb"
each one retaining features of the old quickbasic language.
So you have the choice of writing spaghetti or writing modular code.
end 0
or
end 1
or
end 100
or
end function
where function returns a number
you cannot
end sub
because a sub doesn't return anything.
so main or winmain is always a function if you end main or end winmain.
You don't have to end anything in any program, but the windows examples tend to use end winmain, so that is how it comes about.
If you tag destructor after a sub then that sub will run after the end command is deployed.
It is not hackish and absurd syntax, but useable freebasic syntax.
exit can be used in fb to get out of a sub or function or loop early.
exit in pascal is similar to return in fb inside a function, exit(0), return 0
return is c like, but there are three ways to return in fb.
function dothis as long
return 1
function=1
dothis=1
end function
The fb compiler has several interfaces
#lang "qb"
#lang "fblite"
#lang "fb"
each one retaining features of the old quickbasic language.
So you have the choice of writing spaghetti or writing modular code.