Accessing API in BlitzMax

BlitzMax Forums/BlitzMax Beginners Area/Accessing API in BlitzMax

SebHoll(Posted 2005) [#1]
Hi,

Please can one of your guys explain to me how you access Windows API functions from BlitzMax. I can do this fine in BlitzPlus and I've decided to give Max a shot, but I don't understand what "Extern" does or how you specify which DLL (e.g. user32;kernel32;shell32) you want to take the functions from. Also do you need a userlib as in BlitzPlus?

Thanks in advance, waiting eagerly for a reply :)

Seb


taxlerendiosk(Posted 2005) [#2]
You shouldn't have to specify which DLL to take them from, they're automatically available (I think). You should just be able to define the functions in an Extern block, a lot like you would in a decls file in BlitzPlus.

Extern "win32"
	Function SendMessage:Int(hWnd:Int,MSG:Int,wParam:Int,lParam:Int) = "SendMessageA@16"
End Extern


...at the top of your code is the equivalent of (from memory here :P)

.lib "user32.dll"

SendMessage%(hWnd%,MSG%,wParam%,lParam%):"SendMessageA@16"



SebHoll(Posted 2005) [#3]
Thanks denzilquixode. Just a few questions...

1) What does the "win32" refer to in the Extern function declaration?
2) What does the "@16" mean and where does it come from?
3) Does this mean that all the OS API functions are already declared in the BlitzMax lib folder?

Could anyone please clear me up on these points. Thanks once again,

Seb


taxlerendiosk(Posted 2005) [#4]
The "Win32" bit seems to be optional... not entirely sure what it does, actually, maybe it puts it in a "?Win32 ... ?" block automatically.

@16 means 16 bytes (each int is 4 bytes). It's actually not necessary to specify, I don't think, in most situations. You can just leave that bit out if you never needed it in BlitzPlus.

In the lib directory are .a files for the DLLs, which you could import with
Import "-luser32"

etc. at the top of your code, if you aren't using the standard Blitz modules.


SebHoll(Posted 2005) [#5]
Thanks for clearing that up for me. One more thing that's slighly off-topic. Is there an easy way to read the system environment variables such as %systemroot% or %programfiles% in BlitzMax. The equivalent command in BlitzPlus was GetEnv$().

Thanks for all your help

Seb


skidracer(Posted 2005) [#6]
The "win32" refers to how the aruments are pushed on the stack before the function is called.

Check out the blitzmax/pub.mod/stdc.mod/stdc.bmx file for commands such as getenv_$().


SebHoll(Posted 2005) [#7]
skidracer, I can't find the file you are talking about. I've scanned this folder but there are only *.a and *.i files. (C:\Program Files\BlitzMaxDemo\mod\pub.mod\stdc.mod). I'm currently running the BiltzMax Demo on Windows.

Thanks