While working on one of recent projects, I've stumbled upon few common issues that many meet - even if you are only targeting Windows in GameMaker: Studio, you cannot access files outside the game's AppData directory (not even in program directory). Neither you can order system to open a file, meaning no external "readmes" to be easily hooked up with game, nor portable configuration files, and some other limitations.
So I took an evening and made a simplistic DLL library to bring equivalents to some functions (sleep, execute_shell, non-sandboxed I/O) back for Windows target. Function list is as following:
Identical to pre-Studio sleep(ms) routine. Pauses game execution for given number of milliseconds. For example,
Will pause game execution for 2.5 seconds.
Orders system to do specified action to given file. Common ones are "open", "edit", "print", and availability may vary depending on file type and system configuration.
Identical to execute_shell. You can also use this to open programs with arguments.
shell_execute_at(file, args, directory)
Similar to shell_execute, but you also get to specify working directory for program (or file) ran. This can be useful, if you want to use external tools without specifying absolute paths or having to store them in root of game folder.
Retrieves contents of text file located at given absolute path (no sandboxing) as string. If file does not exist, or an error occurs while retrieving the contents, an empty string is returned.
Replaces contents of file at given path (no sandboxing) with ones provided. If file does not exist, it will be created. Returns, whether the operation was successful.
A more or less precise replica of get_color function from older versions of GameMaker.
A non-sandboxed function for copying files. Note: Uses absolute paths!
In addition, the example attached demonstrates usage of most of these functions.
Example + extension DLL source code
January 23, 2016:
Fixed the issue with file handles not being closed automatically.
The example is now distributed as ZIP to circumvent problems with importing.
Source code is now included in the download and is available separately.
Removed shell_open due to inconsistent behavior on some systems - use shell_do("open", path) instead. Added get_color_win, window_set_caption_ext, file_copy_win.
February 12, 2016:
The DLL no longer requires Visual C++ Runtime to function.
Should help if it previously didn't work for you.
Would installing this extension into my game cause regular functions like “ini_write_real” or “ini_read_string” require an absolute path as well?
Regular functions remain unaffected.
I’ve been doing a bit of testing with this and also with your paid nsfs dll, and I’ve had two users on different Windows OSes so far (one on 7, one on 10) be unable to use any of the file-related functions in WinDev without GM writing a file to the sandbox first. Have you had anything like this happen? Where would I even begin to start trying to figure out the cause?
Sandbox directory does not exist until you write something into it, so if you are doing some operations on that directory, you may need to create it first – either manually via directory_create_ns or just by having GM write anything into it.
Just stumbled across on my search for a shell_execute() command in GMS.
Works great! Thank you so much!
I updated to the latest version GMS 1.4 and the one that you indicated to me to Early Access and error persists
Error: DLL functions with more than 4 arguments can not have string arguments arguments
That’s unfortunate then, one of people working at YoYoGames said on forums in March that it should be fixed in EA.
If you do not have source code for the DLL, you can’t modify it to work with multiple functions or buffers.
You could download a 1.3 version again from the list, but that would have it’s own problems.
In this case, I am barred.
I already downloaded the last version of 2016.
The error persists, it does not allow more than 4 arguments with string.
Hello, can you tell me why gm generates an error when working with more than 4 arguments in a dll. Do you have to get around this situation. Because I’m calling an Api and the function needs to work with 5 mixed arguments. 2 string arguments, 3 real arguments.
If you can, switch to an Early Access version of GameMaker: Studio. It has that fixed already.
Otherwise you’ll need to either split the call into multiple <4arg ones for now, or pass the arguments using a buffer.
When I update it generates conflicts with variables and arguments of some Dlls.
But in version 1.3 that was created the engine runs perfectly.
The dll is third, I can not modify.
Where can I find an example with GM that makes one of two options?
Divide in 4 pars or pass the arguments using a buffer.
Password and LoginID must be of type ty_string and rest of the arguments in ty_real