How do you access win API commands?

BlitzMax Forums/BlitzMax Programming/How do you access win API commands?

JoshK(Posted 2006) [#1]
How do I access the Windows API commands in bmax?


N(Posted 2006) [#2]
Import Pub.Win32

It's worth noting that not all functions are extern'd currently.

So, you do this:
Extern "Win32"
Function FreeLibrary( lhandle:Int )
End Extern



JoshK(Posted 2006) [#3]
So "Import Pub.Win32" turns on access to Win32, then you go through an "extern" each function you need to use?


N(Posted 2006) [#4]
Only if the function isn't already Extern'd in Pub.Win32 (you can either a. wait for a compiler error or b. check the source to see if the function is already Extern'd).


JoshK(Posted 2006) [#5]
Is there a complete set of win32 functions out there already? How about an OpenGL list?


skidracer(Posted 2006) [#6]
Check out the module source code in blitzmax/mod/pub.mod. The next update will have a few more pages of definitions for win32.


N(Posted 2006) [#7]
All OpenGL functions -- extensions included (make sure to call glewInit( ) if you want the extensions, and if you didn't I'd be suprised) -- are accessible.


EOF(Posted 2006) [#8]
I don't know if these files are of any use to you guys.
They are a (large) collection of API constants, Types, and function calls.

Mostly BlitzMax friendly but there is still a lot of stuff which needs stripping out such as

lib "blah"
Alias "whatever"

Conversions I'm not sure about:

Should these entries ..
Field dmDeviceName$ * CCHDEVICENAME
Field bmiColors(0 To 1):RGBQUAD
Function SetupDiDestroyDeviceInfoList(ByRef DeviceInfoSet:Int):Int

Look like this? ..
Field dmDeviceName$ CCHDEVICENAME:Varptr
Field bmiColors:RGBQUAD[0..1]
Function SetupDiDestroyDeviceInfoList:Int(Var DeviceInfoSet:Int)



Win32 API Collection

The files really need breaking up since Notepad struggles with the size.


JoshK(Posted 2006) [#9]
Here is what I tried:

win=CreateWindow("OpenGL Window",200,200,640,480,Null,3)

hwnd=QueryGadget(win,QUERY_HWND_CLIENT)

Extern "Win32"
Function SetClassLong(hwnd:Int,nIndex:Int,dwNewWord:Int)
EndExtern

Const GCL_HBRBACKGROUND=-10

SetClassLong hwnd,GCL_HBRBACKGROUND,0


Here is what the compiler said:
Building test
Compiling:test.bmx
flat assembler  version 1.64
3 passes, 8557 bytes.
Linking:test.debug.exe
E:/Projects/engine/.bmx/test.bmx.gui.debug.win32.o(code+0x1e2): undefined reference to `SetClassLong@12'
Build Error: Failed to link E:/Projects/engine/test.debug.exe
Process complete



BlitzSupport(Posted 2006) [#10]
The Win32 function is actually named SetClassLongA in the DLL (for the normal ASCII version).


kfprimm(Posted 2006) [#11]
change the extren line to
Function SetClassLong(hwnd:Int,nIndex:Int,dwNewWord:Int)="SetClassLongA@12"



JoshK(Posted 2006) [#12]
Cool that works. Yeah, I forgot the end tag.

Now why is it that Extern "OpenGL" fails?


REDi(Posted 2006) [#13]
The bit in the speachmarks defines what calling convention to use, AFAIK it can only be "win32", "c" or "os"


Bremer(Posted 2006) [#14]
="SetClassLongA@12"


Do anyone know where in the docs that part is explained, or could someone explain why its needed on the back of the function definition.


N(Posted 2006) [#15]
>Now why is it that Extern "OpenGL" fails?

Because it's not an OS or language type.

All OpenGL functions are already covered by Pub.OpenGL and Pub.Glew, so just import those.


Dreamora(Posted 2006) [#16]
And for speed reasons: Never use int handles as you did with Blitz Plus, because it will give quite some speed hit which might drop BMs speed below Blitz Plus (for B3D we can say for sure that it drops below)
Always add the type to it (:TGadget for all gui elements for example, TImage for images etc).