Author Topic: DLL function Declaration  (Read 7177 times)

0 Members and 2 Guests are viewing this topic.

Charles Pegge

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


Emil_halim

  • Guest
Re: DLL function Declaration
« Reply #16 on: April 20, 2013, 07:05:51 AM »
Quote
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.
Code: [Select]
function g(sys a,b) external
print  a "   " b
end function

Emil_halim

  • Guest
Re: DLL function Declaration
« Reply #17 on: April 21, 2013, 07:38:44 AM »
Charles ,

con you confirmed that please.

Charles Pegge

  • Guest
Re: DLL function Declaration
« Reply #18 on: April 21, 2013, 01:41:58 PM »
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



Emil_halim

  • Guest
Re: DLL function Declaration
« Reply #19 on: April 22, 2013, 07:58:18 AM »
Hi Charles,

i have an imported function declare as following
Quote
! CreateCamera alias "_CreateCamera@4" (sys EntityParent=0) as sys
inside extern block.

and this is a simple program that using the above declaration
Code: [Select]
//****************************************//
//           ************                 //
//      ***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
Quote
Unidentified operand
WORD: createcamera
Line: 23

so what is that.

Emil_halim

  • Guest
Re: DLL function Declaration
« Reply #20 on: April 22, 2013, 08:16:48 AM »
ok i mead this change
Code: [Select]
//includepath "$/inc/"
$ filename "MagicProTest1.exe"
#include "..\..\inc\RTL32.inc"

#include "MagicPro.inc"

it give an other error
Quote
Linker found unidentified name:
!: level 0

Charles Pegge

  • Guest
Re: DLL function Declaration
« Reply #21 on: April 22, 2013, 08:18:08 AM »
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)

Emil_halim

  • Guest
Re: DLL function Declaration
« Reply #22 on: April 22, 2013, 08:25:38 AM »
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.

Peter

  • Guest
Re: DLL function Declaration
« Reply #23 on: April 22, 2013, 08:34:08 AM »
Quote
while not OIS_isKeyDown(KC_ESCAPE)

Or: 
while  OIS_isKeyDown(KC_ESCAPE) =0


Peter

  • Guest
Re: DLL function Declaration
« Reply #24 on: April 22, 2013, 08:37:11 AM »
Emil,

MagicPro ?

What is it for?

Emil_halim

  • Guest
Re: DLL function Declaration
« Reply #25 on: April 22, 2013, 08:43:53 AM »

Emil_halim

  • Guest
Re: DLL function Declaration
« Reply #26 on: April 22, 2013, 09:19:37 AM »
Charles,

I have this declaration
Quote
! LoadMesh alias "_LoadMesh@12"(char* file, sys EntityParent=0, char* meshName="") as sys


SO when calling it like this the program crash
Code: [Select]
ogrehead = LoadMesh("ogrehead.mesh")

but this works
Code: [Select]
ogrehead = LoadMesh("ogrehead.mesh",0,"")

any help , how to allow empty string "" to be as a default equat?

Aurel

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

Charles Pegge

  • Guest
Re: DLL function Declaration
« Reply #28 on: April 22, 2013, 01:43:09 PM »
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 ...
« Last Edit: April 22, 2013, 08:19:18 PM by Charles Pegge »

Emil_halim

  • Guest
Re: DLL function Declaration
« Reply #29 on: April 22, 2013, 10:02:49 PM »
thanks Aurel,

thanks Charles ,

ok i got it.