Jump to content


Photo

GM DLL


  • Please log in to reply
7 replies to this topic

#1 Master Xilo

Master Xilo

    GMC Member

  • GMC Member
  • 396 posts
  • Version:GM8

Posted 07 July 2012 - 02:57 AM

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).
 
 

Download the GM DLL Extension, including source files and example


Examples

  • 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!

- Paul


Tags
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.

  • 3

#2 Master Xilo

Master Xilo

    GMC Member

  • GMC Member
  • 396 posts
  • Version:GM8

Posted 20 July 2012 - 05:39 PM

Fixed. Renamed original dll_add_directory to dll_set_directory (because that what it actually does as I found out) and added working dll_add_directory. Linked to command help from here instead of including it in the main post.

Fixed sample (didn't specify calling convention).

Same download link.

Edited by Master Xilo, 20 July 2012 - 05:40 PM.

  • 1

#3 Master Xilo

Master Xilo

    GMC Member

  • GMC Member
  • 396 posts
  • Version:GM8

Posted 21 July 2012 - 01:03 AM

Updated to work with GM P6CryptAES, added functions for dealing with c strings and for direct memory access.
  • 0

#4 Mercerenies

Mercerenies

    Koopa King

  • GMC Member
  • 1945 posts
  • Version:GM:Studio

Posted 21 July 2012 - 05:10 AM

Very nice. I'll definitely be using this. +1 :thumbsup:

Edited by Mercerenies, 21 July 2012 - 05:10 AM.

  • 0
iPqfGiP.png

#5 SenJe0

SenJe0

    GMC Member

  • GMC Member
  • 733 posts

Posted 21 July 2012 - 08:25 PM

not getting the AES thing to work :verymad:
  • 0
When I finish University, I would like to work for a BIG software Company like;SENJEN COMPANY. I'm obsessed with them! Period!

#6 Master Xilo

Master Xilo

    GMC Member

  • GMC Member
  • 396 posts
  • Version:GM8

Posted 22 July 2012 - 03:15 PM

Update: Greatly reduced dll file size, added dll_external_define which corresponds to external_define but supports all the additional types defined here. And you can now define arguments right in dll_define, without having to supply the argument count explicitly.

There's also a new function to both define and call a dll function.

Edited by Master Xilo, 22 July 2012 - 03:42 PM.

  • 1

#7 Master Xilo

Master Xilo

    GMC Member

  • GMC Member
  • 396 posts
  • Version:GM8

Posted 13 July 2014 - 09:16 PM

Fixed the link.
  • 0

#8 Alert Games

Alert Games

    GMC Member

  • GMC Member
  • 1119 posts
  • Version:GM8

Posted 14 July 2014 - 09:09 PM

This is very useful. I may be one of the few here, but I like to have only the functionality I need in a project. Sometimes I will use something like the http dll, but other times i'd rather use something a bit more specific, and this saves a lot of time to do so. Nice work


  • 0