DECLS convertion ?

BlitzMax Forums/BlitzMax Programming/DECLS convertion ?

Filax(Posted 2005) [#1]
Hi :)

How i can convert this B3D DECLS entry => BMax ?

.lib "Kernel32.dll"
GetDriveType%(drivename$):"GetDriveTypeA"
GetVolumeInformation%(Path$,VolNameBuff*,VolLen%,Serial*,MaxComponentLen*,fsFlags*,fsNameBuff*,fsNameLen%):"GetVolumeInformationA"
GetLogicalDriveStrings%(bufflen%,buffer*):"GetLogicalDriveStringsA"
GetLogicalDrives%()

Cheers


N(Posted 2005) [#2]
Try:
?Win32
Extern "Win32"
     Function GetDriveType:Int(DriveName:Byte Ptr)="GetDriveTypeA"
End Extern
?


And so on and so forth.


Michael Reitzenstein(Posted 2005) [#3]
$z surely?


Filax(Posted 2005) [#4]
Thanks noel ! but i have a question ? how call this ?

i have try

GetDriveType("D:")

But the compiler say :

C:/BMax/sources/IGlass test/IGlass 1.5/.bmx/Example FileSelector.bmx.o(code+0x358): undefined reference to `GetDriveType@4'


Perturbatio(Posted 2005) [#5]
Print GetDriveType("D:\")
Extern "Win32"
	Function GetDriveType:Int(DrivePath$z) = "GetDriveTypeA@4"
End Extern



Filax(Posted 2005) [#6]
Many many thanks !!!

A last question :) why make :

DrivePath$z

Why the $z ???


Perturbatio(Posted 2005) [#7]
$z is a C-Style null-terminated string.

So if you have a normal blitz string (instead of a string literal), you will probably need to use ToCString to convert it.

*EDIT*
apparently not. It seems to work with a normal Blitz String.


Perturbatio(Posted 2005) [#8]
For future reference, point your command prompt to Bmax/lib and type:
nm [filename] >[filename].txt
to get a listing of the functions available for that lib.

i.e.
nm libwinmm.a >winmm.txt


Filax(Posted 2005) [#9]
Thanks ! it work !


Russell(Posted 2005) [#10]
Forgive the stupid question(s), but:

- What is ?Win32 ... ? Is this a shortcut command of some kind? (I'm not up on all the lingo yet..)

- What does the '@4' at the end of 'GetDriveTypeA' mean?

Thanks,
Russell


Perturbatio(Posted 2005) [#11]
What is ?Win32 ... ? Is this a shortcut command of some kind? (I'm not up on all the lingo yet..)


From what I can tell (and I may be wrong), it is a directive telling the compiler that you are calling a win32 library. It will still compile and run if you remove it, but you get an error when your program exits.

What does the '@4' at the end of 'GetDriveTypeA' mean?


It means the return value is 4 bytes in size. In other words a 32bit integer value.


Yan(Posted 2005) [#12]
Perturbatio (Posted 2005-02-24 02:05:19)
What is ?Win32 ... ? Is this a shortcut command of some kind? (I'm not up on all the lingo yet..)


From what I can tell (and I may be wrong), it is a directive telling the compiler that you are calling a win32 library. It will still compile and run if you remove it, but you get an error when your program exits.

The ?Win32...? just tells BMax to compile that bit only on a Windows system (compiler directive).

The bit that's telling BMax that you are calling a Windows library would be...Extern "Win32"

That's the way I understand it at least. I too could be wrong though ;o)


Perturbatio(Posted 2005) [#13]
oops, stupid me, I was assuming he was referring to the win32 part in the extern command. I never even paid attention to the question marks.


Russell(Posted 2005) [#14]
Well that's good to know that OS-specific compiler directives are available (as long as they're used with care to maintain portability...)

Thanks for the answers. I learn a little bit more each day...

Russell


StuC(Posted 2005) [#15]
Actually, the @4 is the size of the stack for all the pushed parameters, when calling the function.