Oxygen Basic
Programming => Problems & Solutions => Topic started by: Emil_halim on April 19, 2013, 12:43:53 AM
-
Hi Charles,
I was declare a function in Ziron in easy way like that
imports('MagicPro.dll')
{
procedure Graphics3D = ('_Graphics3D@20')(Dword Width,Height,depth=32; boolean fullScrn=false,VSync=false); stdcall;
function make_hgeSprite=('_make_hgeSprite@20')(int32 image_id; single texx,texy, w, h):Dword; stdcall;
procedure DB_LoadMusic=('?DB_LoadMusic@@YGXPADH@Z')(char* szFilename; int32 iID); stdcall;
}
So i tried to convert it like this
extern lib "MagicPro.dll"
! Graphics3D alias _Graphics3D@20(Dword Width,Height,depth=32, boolean fullScrn=false,VSync=false)
! make_hgeSprite alisa _make_hgeSprite@20(int32 image_id; single texx,texy, w, h) as Dword
! DB_LoadMusic alisa ?DB_LoadMusic@@YGXPADH@Z
is this correct and if there is a simpler other method please tell me.
-
Hi Emil
extern lib "MagicPro.dll"
! Graphics3D alias _Graphics3D@20(Dword Width,Height,depth=32, boolean fullScrn=false,VSync=false)
! make_hgeSprite alisa _make_hgeSprite@20(int32 image_id; single texx,texy, w, h) as Dword
! DB_LoadMusic alisa ?DB_LoadMusic@@YGXPADH@Z
Everything is wrong!
extern lib "MagicPro.dll"
! Graphics3D Alias " _Graphics3D@20"
! make_hgeSprite Alias " _make_hgeSprite@20"
! DB_LoadMusic Alias " ?DB_LoadMusic@@YGXPADH@Z"
end extern
-
Hi Peter,
thank you very much.
i have collect many different method to import Dll function. need some one to comment it
and demonstrate each case please.
=======================================================
! IupOpen Lib "iup.dll" (sys a,b) as sys
! IupCreate Lib "iup.dll" (string cname) as sys
! iupDrawRectangle Lib "iup.dll" (sys *dc, x1, y1, x2, y2, byte r, g, b, sys style)
! IupMainLoopLevel Lib "iup.dll" () as sys
! IupClose Lib "iup.dll" ()
' Example
=========
IupOpen(0,0)
win = iupCreate "dialog"
iupDrawRectangle *canvas, 0,0, 244,238, 254,72,170, 1
IupClose()
===========================================================================
Declare Function DragQueryFile Lib "shell32" Alias "DragQueryFileA" ( _
ByVal wHandle As SYS, _
ByVal NumFiles As SYS, _
ByVal NameBuffer As SYS, _
ByVal BufferLen As Long) As SYS
DECLARE SUB DragAcceptFiles LIB "SHELL32.DLL" ALIAS "DragAcceptFiles" ( _
BYVAL hWnd AS SYS _ ' __in HWND hWnd
, BYVAL fAccept AS SYS _ ' __in BOOL fAccept
) ' void
declare sub trial alias "trial" lib "mdlt"
declare QueryPerformanceCounter lib "kernel32.dll" (quad *c)
===========================================================================
gdi32 = LoadLibrary "gdi32.dll"
Bind gdi32
(
ChoosePixelFormat ChoosePixelFormat
SetPixelFormat SetPixelFormat
GetStockObject GetStockObject
SwapBuffers SwapBuffers
)
============================================================================
lib "gdi32.dll"
Declare Polygon (sys hdc, int *lpPoints, nCount) as bool
Declare ...
lib ""
Library "user32.dll"
! MessageBox alias "MessageBoxA"
Library ""
=============================================================================
extern lib "gdi32.dll"
! CreateFont Alias "CreateFontA" (long H,W,E,O,W,I,U,S,C,OP,CP,Q,PAF,string F) As sys
! alias FreeImage_OutputMessageProc
! alias _FreeImage_GetVersion@0() as char*
end extern
extern lib "sqlite3.dll"
sys sqlite3_open (char*name,sys*db)
sys sqlite3_exec (sys db,char* s, sys p1, sys p2, sys*dberr)
sys sqlite3_prepare_v2 (sys db, char*s, sys p1, sys*stmt, sys p2)
sys sqlite3_step (sys n)
char* sqlite3_column_text (sys row, sys col)
sys sqlite3_close (sys db)
'
end extern
================================================================================
module o2
declare sub ::message alias "message" lib "sbo2"
declare sub ::compile alias "compile" lib "sbo2"
declare sub ::start alias "start" lib "sbo2"
declare sub ::fun alias "fun" lib "sbo2"
end module
================================================================================
Also , what about optional param in first function
-
Hi Emil,
The final on your list is for ScriptBasic :)
'!' is the same as declare
You can use the word optional for optional parameters. The compiler pushes nulls onto the stack wherever the optional param is not specified in a call.
Any param specified to the right of optional is optional.
! IupOpen Lib "iup.dll" (optional sys a,b) as sys
Charles
-
Hi Charles,
for the sake of simplicity.
can you allow C++ style instead of Optional keyword
E.G
! IupOpen Lib "iup.dll" (sys a=0,b) as sys
-
Use of the default equate is subtly different, you will still need the word optional
function f(sys optional a=1,b=0)
print a " " b
end function
f ' 1 0
f 48 ' 48 0
f 48,96 ' 48 96
f a=12 ' 12 0
f b=24 ' 1 24
f a=6,b=12 ' 6 12
-
yes but i need it with Dll import function
-
It should still work with a DLL import
Emulated here:
function g(sys optional a=1,b=0) external
print a " " b
end function
declare function f(sys optional a=1,b=0) at g
f ' 1 0
f 48 ' 48 0
f 48,96 ' 48 96
f a=12 ' 12 0
f b=24 ' 1 24
f a=6,b=12 ' 6 12
-
ok , but i did not like it in this way.
can you support it with any method of declaration tha i listed above.
also con you make optional keyword optional here so default equate will tell the compile that it is optional.
Any param specified to the right of optional is optional.
hum... suppose that i want b param is required and keeping the order of parameters , i think default equate
is the good solution here . for Exam
! IupOpen Lib "iup.dll" (sys a=0,b) as sys
-
ok , but i did not like it in this way.
heh ..that is the main trick here ;)
I don't like some things in o2 -> but most of things is great
even better than in some other compilers... :)
-
I don't like some things in o2 -> but most of things is great
even better than in some other compilers
workaround solution and achieving a certain thing by many ways is the best advantage of OxyGen Basic.
-
Hi Charles,
deos the latest update applies to import function?
-
Sure, here is another function vector declaration
function g(sys a,b) external
print a " " b
end function
! f(sys a=1,b) at g
f ' 1 0
f 48 ' 48 0
f 48,96 ' 48 96
f a=12 ' 12 0
-
ok Charles ,
but i want it just like that
! f(sys a=1,b)
because i have many imported functions those have default equate , so for each function i have to declare this
function g(sys a,b) external
print a " " b
end function
hope you get me well.
thanks you.
-
hmm...
in which another language you can define such a construction ???
-
You can use extern blocks for all the imported functions. Then no need to repeat lib, calling-convention, external.
extern lib "user32.dll"
! Sleep(int ms)
...
extern lib cdecl "mylib.dll"
! f(sys a=1,b)
...
end extern
-
Then no need to repeat lib, calling-convention, external.
is that mean there is no need to declare the following dummy function to allow optional parameters of
my imported dll functions when using extern blocks.
function g(sys a,b) external
print a " " b
end function
-
Charles ,
con you confirmed that please.
-
Yes Emil, it will give you optional param with the syntax used above. However during the course of my checks, I found some anomalies, with mixed optional and default value calls, which I will need to fix. But for your optional params, it should be okay.
extern lib "tdll.dll"
! ff1(sys a=0,b,c,d) as sys1
end extern
ff1 2,3
------->
includepath "$/inc/"
$filename "tdll.dll"
$dll
include "RTL32.inc"
extern export
function ff1(sys a,b,c,d) as sys
string cm=","
print a cm b cm c cm d
end function
-
Hi Charles,
i have an imported function declare as following
! CreateCamera alias "_CreateCamera@4" (sys EntityParent=0) as sys
inside extern block.
and this is a simple program that using the above declaration
//****************************************//
// ************ //
// ***MagicPro library*** //
// ************ //
//****************************************//
includepath "$/inc/"
$ filename "Scaling.exe"
#include "RTL32.inc"
#include 'MagicPro.inc';
sys cam
Init("MagicPro Test #1")
Graphics3D(800,600)
setMediaDir("ZipMedia.zip")
setMediaDir("media")
setAmbientLight(30.0,30.0,50.0)
cam = CreateCamera
while(!OIS_isKeyDown(KC_ESCAPE))
{
RenderWorld()
Sync()
}
EndGraphics()
when compiling got that funny errer
Unidentified operand
WORD: createcamera
Line: 23
so what is that.
-
ok i mead this change
//includepath "$/inc/"
$ filename "MagicProTest1.exe"
#include "..\..\inc\RTL32.inc"
#include "MagicPro.inc"
it give an other error
Linker found unidentified name:
!: level 0
-
Spotted 2 errors
Need to replace single quotes with double quotes?
#include 'MagicPro.inc';
also:
while(!OIS_isKeyDown(KC_ESCAPE))
while not OIS_isKeyDown(KC_ESCAPE)
-
thanks Charles ,
works now .
but i have an idea about includepath , noticed that when using it , any file in the o2bas folder did not seen
by Oxygen , SO you can use array of include paths and searching will be one after one.
-
while not OIS_isKeyDown(KC_ESCAPE)
Or:
while OIS_isKeyDown(KC_ESCAPE) =0
-
Emil,
MagicPro ?
What is it for?
-
Hi Peter,
see my last post in this page http://www.ogre3d.org/forums/viewtopic.php?f=11&t=25924&start=375 (http://www.ogre3d.org/forums/viewtopic.php?f=11&t=25924&start=375)
-
Charles,
I have this declaration
! LoadMesh alias "_LoadMesh@12"(char* file, sys EntityParent=0, char* meshName="") as sys
SO when calling it like this the program crash
ogrehead = LoadMesh("ogrehead.mesh")
but this works
ogrehead = LoadMesh("ogrehead.mesh",0,"")
any help , how to allow empty string "" to be as a default equat?
-
maybe :
ogrehead = LoadMesh("ogrehead.mesh",0,NULL)
by the way i read somewhere that char cannot have 0 length so probably must
be string with zero length.
-
Hi Emil, Altering the compiler for this one, creates logistical nightmares so the best solution is:
LoadMesh alias "_LoadMesh@12"(char* file="", sys EntityParent=0, char* meshName="") as sys
...
ogrehead = LoadMesh(file="ogrehead.mesh")
PS:
Another way is to check for null strings within the procedure you are calling (if this is your own library):
if not strptr MeshName then ...
-
thanks Aurel,
thanks Charles ,
ok i got it.
-
Chales ,
how to declare an import function as a c function "cdecl" ?
-
cdecl can go into the xtern statement, if it applies to several functions, or it can be applied to individual functions:
extern lib "mylib.dll" cdecl
! myproc alias "MyProc" (..)
end extern
extern lib "mylib.dll"
! myproc cdecl alias "MyProc" (..)
end extern
-
yes that will help me a lot, thanks Charles.