The built in functions for dealing with dlls only support double and char* arguments and return values. However there are many more datatypes dll functions usually accept, one important one being 32 bit size integers. This extension provides a new and open source interface to loading and calling functions from dlls enabling wrapping from within Game Maker. This allows to extend the Game Maker with readily available functionality from within it's own language where otherwise a wrapper dll and extension would have to be used.
You will mostly use the following functions: dll_load, dll_define, dll_add_arg, dll_call
Note: dll_load and dll_define only work in Game Maker 8.1+ because they use argument_count. Use the hidden dll_define_ and dll_load_ functions on lower versions. GM P6CryptAES shows an example of this (you need to pass the remaining 16 arguments as 0 to dll_define_ and must manually convert strings for dll_call_ with dll_s2r).
- Here's how we can easily download a file by using urlmon.dll and URLDownloadToFile:
DWORD URLDownloadToFile( DWORD pCaller, char* szURL, char* szFileName, DWORD dwReserved, DWORD lpfnCB );All WINAPI functions use the stdcall calling convention (callee clears the stack, not caller). We don't care about any arguments but the 2nd and 3rd.
dll = dll_load("Urlmon.dll"); fid = dll_define(dll, "URLDownloadToFileA", dll_stdcall, ty_dword); dll_add_arg(fid, ty_dword); dll_add_arg(fid, ty_string); dll_add_arg(fid, ty_string); dll_add_arg(fid, ty_dword); dll_add_arg(fid, ty_dword); callres = dll_call(fid, 0, "http://dl.dropbox.com/u/8014211/WebsiteMedia/logohceent.png", working_directory + "\test.png", 0, 0);(Note that actually, char* are also DWORDs, but we need to do some conversion so we don't declare them the same way)
- The demo .gm81 included shows how to use the WinApi dlls through this to:
- Delete a directory (implement a "directory_delete" (not implemented by Game Maker) with RemoveDirectory)
- Download a file
- Position the cursor on the screen with absolute coordinates (using Win Api SetCursorPos - this can also be done with the builtin display_mouse_set(x,y)).
- The encryption solution GM P6CryptAES uses this to avoid having to write a wrapper dll.
I hope you'll find it useful!
game maker position cursor absolute screen coordinates, game maker winapi dll call, gmdll, game maker dll ext, gm dll ext, game maker advanced dll extension
Edited by Master Xilo, 23 August 2015 - 02:08 PM.