O2 from Powerbasic?

Started by Theo Gottwald, December 21, 2023, 06:28:45 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

Theo Gottwald

Is anyone aware of how to utilize O2 as a DLL with PowerBasic for various tasks? 🤔💡
Are there Samples available?

#PowerBasic #Programming #Coding #DLL #Oxygen #TechTips 🧑�💻📚🔍💻🔄🔌

O2Basic.png

Zlatko Vid

Why you want put Oxygen basic as Power basic DLL?
Oxygen Basic is standalone compiler which don't need Power Basic
so i don't understand your point or your question?

Theo Gottwald

#2
I'm pondering 🤔 whether I could integrate this into my existing apps, but I'm stumped 🤷�♂️. What's its purpose, how does it operate, and what's its name?
If anyone's got a snippet, I'd love a simple example of how to call and use it in PowerBasic.
Just the basics would be great! 🙏

#TechHelp #PowerBasic #CodingCommunity #DevTalk #ProgrammingTips #CodeSnippet #LearningToCode 🧑�💻👩�💻🔍📚🖥�👨�🏫👩�🏫

In Powerbasic's sea, I swim with a smirk, 🦈
Understanding its essence, both mighty and stark. 🌟
A DLL crystal clear, not a hint of a fog, 🌫�
Should be linked in with joy, like a dance with a clog. 🕺

Why not sip from the source, oh so pure and so belle? 🍷
In Powerbasic's waters, it would ring like a bell! 🔔
Could a soul lend a hand, with an example so fine, 🤲
Small and simple, for life to be breezy as brine? 🌊

With this DLL, step by tender step, 🐾
A pattern to show us the groove, with some pep! 💃
The other examples, a maze in my head, 🌀
They don't click, my brain's hitting red. 🛑

So who's up for the task, got the time, got the knack? ⏰
To pen down a sample, that's easy, not whack? ✍️
In Powerbasic's tongue, so I get the gist, 🗣�
And use that DLL, with a joyful twist. 🎉

Charles Pegge

Hi Theo,

I've forgotten PowerBasic but this FreeBasic should be easy to adapt:

  extern "windows-MS" lib "oxygen"

  declare sub      o2_mode  (byval m as long)
  declare function o2_abst  (byval p as zstring ptr) as zstring ptr
  declare sub      o2_basic (byval p as zstring ptr)
  declare function o2_exec  (byval addr as long) as long
  declare function o2_buf   (byval n as long) as long
  declare function o2_errno () as long
  declare function o2_error () as zstring ptr
  declare function o2_len   () as long
  declare function o2_prep  (byval p as zstring ptr) as zstring ptr
  declare function o2_view  (byval p as zstring ptr) as zstring ptr

O2 source code is passed for compilation using o2_basic(src)
Errors are returned using o2_error()
Successfully compiled code is run using o2_exec(0)


Theo Gottwald

Hallo Charles,
where can i see a working sample?
Also "z string p" is nothing i can use in Powerbasic.
Then i also do not understand what i can do with the compiled code.
Can it be saved in a file or is "ready to be linked" ...
Where can i read all this?

Charles Pegge

I remember! It's asciiz instead of zstring for Power Basic.

This information is only of use if you are designing an embedded system or new Compiler. co2.exe is the main user of oxygen.dll

My untested simple example:
'HOW TO USE OXYGEN DLL
'22/12/2023 CP
  extern lib "oxygen.dll"
    declare function o2_basic(byref s as asciiz) as long
    declare function o2_exec (byval p as long) as long
    declare function o2_errno() as long
    declare function o2_error() as asciiz ptr
  end extern
  '
  dim qu as string
  dim cr as string
  dim src as string
  qu=chr(34)
  cr=chr(13)+chr(10)
  src="print " + qu+"Helo"+qu+cr
  '
  o2_basic(src)
  '
  if o2_errno()<>0
    print o2_error()
  else
    o2_exec(0)
  end if
  end

This is a list of source files citing o2_exec
.\demos\!ProjB\ThinBasicOxygen\thinBasic_Oxygen.o2bas
.\inc\self\co2m64.o2bas
.\inc\self\co2m641.o2bas
.\inf\testlog2.o2bas
.\tools\co2.o2bas
.\tools\co2m64.o2bas
.\demos\!ProjB\ThinBasicOxygen\Examples\GuiTbglO2\MainFunctions.inc
.\inc\OxygenAPI.inc
.\inc\OxygenApiLateBinding.inc
.\inc\self\main.inc
.\tools\Gxo2Fb\xo2.inc

Charles Pegge

#6
Because OxygenBasic uses OleStrings, the same as Powerbasic, it is possible to make the Oxygen API slightly more compatible by calling o2_mode 9. This instructs Oxygen.dll to use Ansi Olestrings instead of null-terminated char / asciiz.

  extern lib "oxygen.dll"
    declare function o2_basic(byval s as string) as long
    declare function o2_exec (byval p as long) as long
    declare function o2_errno() as long
    declare function o2_error() as string
    declare function o2_mode(byval m as long)
  end extern
  '
  dim qu as string
  dim cr as string
  dim src as string
  qu=chr(34)
  cr=chr(13)+chr(10)
  src="print " + qu+"Helo"+qu+cr
  '
  o2_mode 9
  o2_basic(src)
  '
  if o2_errno()<>0
    print o2_error()
  else
    o2_exec(0)
  end if
  end

Available modes:
  /**
    specify string mode for various o2 API functions
    0 ascii char*
    1 ascii char*
    2 wchar*
    8 ole bstring ascii
    9 ole bstring ascii
    10 ole wbstring wide chars
  */

Theo Gottwald

Seems you really forgot all about Powerbasic, Charles.
Thanks for the sample that will allow to experiment with it.