• Welcome to Jose's Read Only Forum 2023.
 

Hello world not firing.

Started by Brian Alvarez, October 04, 2018, 03:24:43 AM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

Brian Alvarez

 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


Brian Alvarez

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.

Mike Lobanovsky

#2
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.
Mike
(3.6GHz Intel Core i5 w/ 16GB RAM, 2 x GTX 650Ti w/ 2GB VRAM, Windows 7 Ultimate Sp1)

Mike Lobanovsky

Oh,

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

Thanks Roland! :)
Mike
(3.6GHz Intel Core i5 w/ 16GB RAM, 2 x GTX 650Ti w/ 2GB VRAM, Windows 7 Ultimate Sp1)

Charles Pegge

The same applies to o2-compiled DLLS. There is no DLLmain, and the code is directly executed as soon as the DLL is loaded.

José Roca

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?

Zlatko Vid

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.

José Roca


Brian Alvarez

Yes, that worked fine Guys, i now get a messagebox as expected, but i second Jose's question regarding DLLs.

José Roca

#9
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

Charles Pegge

#10
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





Chris Chancellor

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

Charles Pegge

#12
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


Chris Chancellor

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()




Charles Pegge

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)