The following code is being generated for a hello world example. But no message ox is being triggered.
What can i be doing wrong?
'Generated with PluriBASIC 6.0.74371.0
$ filename "hello_world.exe"
uses rtl64
' STARTS PLURIBASIC_INIT.BIN
' Enter the stock code and functions here.
' END OF PLURIBASIC_INIT.BIN
' STARTS MSGBOX.BIN
FUNCTION MSGBOX(string sText, sys mOptions = 0, string sCaption = "") AS LONG
mbox(sText)
END FUNCTION
' END OF MSGBOX.BIN
' STARTS CALLBACKDATA.BIN
' CALLBACK data
' END OF CALLBACKDATA.BIN
' STARTS ENTRY_POINT.BIN
' Enttry point code
' END OF ENTRY_POINT.BIN
' Initializes various things in the script.
FUNCTION PluriBASIC_Initialize() AS LONG
END FUNCTION
FUNCTION MAIN()
MSGBOX "hello world"
END FUNCTION
Forgot to mention, the code apparently compiles fine, as a 15kb 64 bits executable: hello_world.exe
but when the IDE executes it, no errors occur and no messageboxes appear. The windows explorer
does the same.
Brian,
Unlike PowerBASIC, OxygenBasic doesn't run its main() function automatically. All O2 functions in the script are functionally equal as possible app entry points.
You have to call it explicitly somewhere in your module level code, in this case immediately after the uses rtl64 statement if PB6 follows Oxygen's lookahead directive implicitly, or at the very end of the script if it doesn't.
Oh,
And I've just noticed a similar message by Arnold (a.k.a. Roland) addressed to you on the OxygenBasic forum.
Thanks Roland! :)
The same applies to o2-compiled DLLS. There is no DLLmain, and the code is directly executed as soon as the DLL is loaded.
Quote from: Charles Pegge on October 04, 2018, 04:45:52 PM
The same applies to o2-compiled DLLS. There is no DLLmain, and the code is directly executed as soon as the DLL is loaded.
Then what happens if I need to do some initialization and/or cleanup work?
QuoteThen what happens if I need to do some initialization and/or cleanup work?
It is easy use GOSUB for intialization
and for CleanUp jump to the END.
I was talking of DLLs.
Yes, that worked fine Guys, i now get a messagebox as expected, but i second Jose's question regarding DLLs.
If the code is directly executed as soon as the DLL is loaded, we can know when it has been loaded and do initialization work, but we won't know when the DLL has been unlodaded.
Free Basic doesn't use a LibMain, but you can use a constructor and a destructor.
SUB ctor () CONSTRUCTOR
END SUB
SUB dtor () DESTRUCTOR
END SUB
In o2 DLLs,your initialisation code goes in directly, everything else is in procedures.
If you require cleanup before the DLL is unloaded, this goes into a sub called finish. The final line of this procedure must be terminate, which invokes o2's internal cleanup. But o2 will otherwise generate its own finish()
sub finish() external
...
terminate
end sub
QuoteIn o2 DLLs,your initialisation code goes in directly, everything else is in procedures.
Hello Charles
why not provide us an example code for a dll so that we can test it fully?
especially we need to know where to place its main() and terminate
Thanxx a lot
A minimal DLL showing loading and unloading:
$dll
$filename "t.dll"
uses rtl64
print "loading"
sub hello() export
print "Hello World!"
end sub
sub finish() external
print "unloading"
...
terminate
end sub
Thanxx a lot Charles
Does O2 DLL always run sequentially from top to bottom of its module?
when executing your t.dll
i notice that it will execute in these phases :
1. Display "Loading"
2. Display "Hello World!"
3. Display "unloading"
4. terminate
even without explicitly calling hello() and finish()
Testing the DLL:
extern lib "t.dll"
! hello()
end extern
hello()
Loading and unloading DLLs can also be done explicitly:
sys lt=LoadLibrary("t.dll")
sys gp=GetProcAddress(lt,"hello")
extern
! Hello() at gp
end extern
Hello()
...
FreeLibrary(lt)
Thanxx a lot Charles
the second Caller example looks more structure