How do you access win API commands?
BlitzMax Forums/BlitzMax Programming/How do you access win API commands?
| ||
How do I access the Windows API commands in bmax? |
| ||
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 |
| ||
So "Import Pub.Win32" turns on access to Win32, then you go through an "extern" each function you need to use? |
| ||
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). |
| ||
Is there a complete set of win32 functions out there already? How about an OpenGL list? |
| ||
Check out the module source code in blitzmax/mod/pub.mod. The next update will have a few more pages of definitions for win32. |
| ||
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. |
| ||
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. |
| ||
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 |
| ||
The Win32 function is actually named SetClassLongA in the DLL (for the normal ASCII version). |
| ||
change the extren line toFunction SetClassLong(hwnd:Int,nIndex:Int,dwNewWord:Int)="SetClassLongA@12" |
| ||
Cool that works. Yeah, I forgot the end tag. Now why is it that Extern "OpenGL" fails? |
| ||
The bit in the speachmarks defines what calling convention to use, AFAIK it can only be "win32", "c" or "os" |
| ||
="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. |
| ||
>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. |
| ||
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). |