Jose's Read Only Forum 2023

IT-Consultant: Charles Pegge => OxygenBasic => Topic started by: Brian Alvarez on October 04, 2018, 03:24:43 AM

Title: Hello world not firing.
Post by: Brian Alvarez on October 04, 2018, 03:24:43 AM
 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

Title: Re: Hello world not firing.
Post by: Brian Alvarez on October 04, 2018, 03:28:17 AM
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.
Title: Re: Hello world not firing.
Post by: Mike Lobanovsky on October 04, 2018, 09:48:41 AM
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.
Title: Re: Hello world not firing.
Post by: Mike Lobanovsky on October 04, 2018, 09:59:08 AM
Oh,

And I've just noticed a similar message by Arnold (a.k.a. Roland) addressed to you on the OxygenBasic forum.

Thanks Roland! :)
Title: Re: Hello world not firing.
Post by: 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.
Title: Re: Hello world not firing.
Post by: José Roca on October 04, 2018, 05:12:09 PM
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?
Title: Re: Hello world not firing.
Post by: Zlatko Vid on October 04, 2018, 08:00:18 PM
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.
Title: Re: Hello world not firing.
Post by: José Roca on October 04, 2018, 08:22:58 PM
I was talking of DLLs.
Title: Re: Hello world not firing.
Post by: Brian Alvarez on October 04, 2018, 09:02:26 PM
Yes, that worked fine Guys, i now get a messagebox as expected, but i second Jose's question regarding DLLs.
Title: Re: Hello world not firing.
Post by: José Roca on October 04, 2018, 09:22:20 PM
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
Title: Re: Hello world not firing.
Post by: Charles Pegge on October 05, 2018, 11:56:43 AM
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




Title: Re: Hello world not firing.
Post by: Chris Chancellor on October 05, 2018, 03:37:35 PM
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
Title: Re: Hello world not firing.
Post by: Charles Pegge on October 06, 2018, 02:50:53 PM
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

Title: Re: Hello world not firing.
Post by: Chris Chancellor on October 06, 2018, 07:16:30 PM
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()



Title: Re: Hello world not firing.
Post by: Charles Pegge on October 07, 2018, 03:55:21 AM
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)

Title: Re: Hello world not firing.
Post by: Chris Chancellor on October 07, 2018, 06:56:06 PM
Thanxx a lot Charles

the second Caller example looks more structure