Author Topic: DLL function Declaration  (Read 7176 times)

0 Members and 1 Guest are viewing this topic.

Emil_halim

  • Guest
DLL function Declaration
« on: April 19, 2013, 12:43:53 AM »
Hi Charles,

I was declare a function in Ziron in easy way like that
Code: [Select]
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
Code: [Select]
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.

Peter

  • Guest
Re: DLL function Declaration
« Reply #1 on: April 19, 2013, 02:13:28 AM »
Hi Emil

Quote
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

Emil_halim

  • Guest
Re: DLL function Declaration
« Reply #2 on: April 19, 2013, 03:54:18 AM »
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.
Code: [Select]

=======================================================

! 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
« Last Edit: April 19, 2013, 04:01:28 AM by Emil_halim »

Charles Pegge

  • Guest
Re: DLL function Declaration
« Reply #3 on: April 19, 2013, 06:12:25 AM »
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




Emil_halim

  • Guest
Re: DLL function Declaration
« Reply #4 on: April 19, 2013, 06:23:58 AM »
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  
« Last Edit: April 19, 2013, 07:00:11 AM by Emil_halim »

Charles Pegge

  • Guest
Re: DLL function Declaration
« Reply #5 on: April 19, 2013, 07:13:11 AM »
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

Emil_halim

  • Guest
Re: DLL function Declaration
« Reply #6 on: April 19, 2013, 07:16:53 AM »

yes but i need it with Dll import function

Charles Pegge

  • Guest
Re: DLL function Declaration
« Reply #7 on: April 19, 2013, 07:47:35 AM »
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

Emil_halim

  • Guest
Re: DLL function Declaration
« Reply #8 on: April 19, 2013, 08:01:49 AM »

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.

Quote
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
Code: [Select]
! IupOpen  Lib "iup.dll" (sys a=0,b) as sys 
 

Aurel

  • Guest
Re: DLL function Declaration
« Reply #9 on: April 19, 2013, 10:43:29 AM »
Quote
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... :)

Emil_halim

  • Guest
Re: DLL function Declaration
« Reply #10 on: April 19, 2013, 10:56:05 AM »
Quote
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.   

Emil_halim

  • Guest
Re: DLL function Declaration
« Reply #11 on: April 19, 2013, 11:52:54 AM »

Hi Charles,

deos the latest update applies to import function?

Charles Pegge

  • Guest
Re: DLL function Declaration
« Reply #12 on: April 19, 2013, 12:58:51 PM »
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

Emil_halim

  • Guest
Re: DLL function Declaration
« Reply #13 on: April 19, 2013, 01:07:30 PM »

ok Charles ,

but i want it just like that
Code: [Select]
! f(sys a=1,b)

because i have many imported functions those have default equate , so for each function i have to declare this
Code: [Select]
function g(sys a,b) external
print  a "   " b
end function

hope you get me well.

thanks you.
 

Aurel

  • Guest
Re: DLL function Declaration
« Reply #14 on: April 19, 2013, 01:23:14 PM »
hmm...
in which another language you can define such a construction  ???