' version oxygen.dll from ca 2014 until 2017
' liboxygen.dll.a, compiled with freebasic
'FB compiling:
'fbc FBHost.bas
'fbc -s gui FBHost.bas
' o2_basic(t) I have changed only here below for execution
' result output (ok)
5
7.071067811865476
'
'FreeBasic App Hosting Embedded OxygenBasic
'==========================================
' Charles Pegge
' 22:06 18/06/2014
'
' 10-12-2024, test frank bruebach, freebasic version 1.10.1
' o2_basic(t) I have changed here below for execution
'FB compiling:
'fbc FBHost.bas
'fbc -s gui FBHost.bas
'------------
'SELECTED API
'============
'
'#include once "windows.bi"
'#include once "win/ole2.bi"
'
#define DLL_PROCESS_ATTACH 1
#define DLL_THREAD_ATTACH 2
#define DLL_THREAD_DETACH 3
#define DLL_PROCESS_DETACH 0
#define DLL_PROCESS_VERIFIER 4
#define sys Long
Type HWND As sys
Type HMODULE As sys
Type HINSTANCE As sys
Type BOOL As sys
Type UINT As sys
Type DWORD As sys
Type BSTR As Any Ptr
Type FARPROC As Any Ptr
Type PVOID As Any Ptr
Type PCVOID As Any Ptr
Type PLONG As Long Ptr
Type PDWORD As dword Ptr
Type LPCSTR As Zstring Ptr
Type LPSECURITY_ATTRIBUTES As Any Ptr
Type LPOVERLAPPED As Any Ptr
Type HANDLE As sys
#define iostring bstr
'
Extern "windows" lib "kernel32"
Declare Function ReadFile ( _
As HANDLE, _
As PVOID, _
As DWORD, _
As PDWORD, _
As LPOVERLAPPED) As BOOL
Declare Function WriteFile ( _
Byval As HANDLE, _
As PCVOID, _
As DWORD, _
As PDWORD, _
As LPOVERLAPPED) As BOOL
Declare Function LoadLibrary Alias "LoadLibraryA" ( _
As LPCSTR) As HINSTANCE
Declare Function CreateFile Alias "CreateFileA" ( _
As LPCSTR, _
As DWORD, _
As DWORD, _
As LPSECURITY_ATTRIBUTES, _
As DWORD, _
As DWORD, _
As HANDLE) As HANDLE
Declare Function FreeLibrary(Byval As HMODULE) As BOOL
Declare Function GetProcAddress( _
As HINSTANCE, _
As LPCSTR) As FARPROC
Declare Function GetFileSize ( _
As HANDLE, _
As PDWORD) As DWORD
Declare Function SetFilePointer( _
As HANDLE, _
As Long, _
As PLONG, _
As DWORD) As DWORD
Declare Function CloseHandle( _
As HANDLE) As BOOL
End Extern
Extern "windows" lib "oleaut32"
Declare Function SysAllocStringByteLen ( _
As Zstring Ptr, _
As Uinteger) As BSTR
Declare Sub SysFreeString (Byval As BSTR)
End Extern
Extern "windows" lib "user32"
Declare Function MessageBox Alias "MessageBoxA" ( _
As HWND, _
As LPCSTR, _
As LPCSTR, _
As UINT) As Integer
End Extern
#define AllocString(p,le) SysAllocStringByteLen(p,le)
#define FreeString(p) SysFreeString(p)
#define Library(s) LoadLibrary(s)
#define FreeLibr(a) FreeLibrary(a)
#define ProcAddr(a,b) GetProcAddress(a,b)
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_asmo (byval p as zstring ptr)
declare sub o2_basic (byval p as zstring ptr)
declare function o2_exec (byval addr as long) as any ptr
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_get () as zstring ptr
declare function o2_len () as long
declare function o2_prep (byval p as zstring ptr) as zstring ptr
declare sub o2_put (byval c as bstr)
declare function o2_view (byval p as zstring ptr) as zstring ptr
'DECLARE PROCEDURES IN OXYGEN PROGRAM
'====================================
dim shared hypot2d as function(byval x as double, byval y as double) as double
dim shared hypot3d as function(byval x as double, byval y as double, byval z as double) as double
dim shared finish as function() as long
dim shared as string cr
end extern
type FunctionTable
f(100) as any ptr
end type
'
'------------------------------
function SetupProgram() as long
'==============================
dim as string s
dim as string t
dim as any ptr pt
dim as long le
cr=chr(13)+chr(10)
'
'LOAD SOURCE FILE
'================
'
s="OxJitLib.o2bas"
open s for binary access read as 2
le=lof(2)
t=string(le,chr(0))
get #2,,t
close 2
'
'
if t="" then
print "error 3: file empty or not found: "+s
return 0
end if
'
'
'OXYGEN COMPILE
'==============
o2_mode(0) 'read/return null terminated ascii strings
' o2_asmo(t) 'compile string ' -> doesnt work with newer oxygen.dll version
o2_basic(t) ' that's needed for execution
'
if o2_errno then
print * o2_error()
return 0
else
pt = o2_exec(0) 'EXECUTE OXYGEN PROGRAM - RETURNS FUNCTION TABLE POINTER
end if
'MAP FUNCTIONS
'=============
static as FunctionTable ptr ft
ft=pt
hypot2d = ft->f(0)
hypot3d = ft->f(1)
finish = ft->f(2)
return 1
end function
'
'
if SetupProgram() then
print hypot2d(3.0, 4.0) '5.0
print hypot3d(3.0, 4.0,5.0) '5.0
'...
finish() 'RELEASE OXYGEN PROGRAM
end if
'======
sleep
' end
'
' oxygen file to load
' oxjitlib.o2bas
extern
function hypot2d(double a,double b) as double
return sqr( a*a+b*b)
end function
function hypot3d(double a,double b, double c) as double
return sqr( a*a+b*b+c*c)
end function
function finish() as sys
terminate
end function
end extern
sys table={@hypot2d, @hypot3d, @finish}
= @table
' end
Page created in 0.089 seconds with 11 queries.