• Hey! Guest! The 36th GMC Jam will take place between February 27th, 12:00 UTC - March 2nd, 12:00 UTC. Why not join in! Click here to find out more!

GMS 2 [SOLVED] Has something changed with C++ dlls?


NOTE: I don't want advice on how to create an extension. My question is about writing dlls and calling functions from them. Unless the only way to use a dll is now only by an extension, please don't discuss extensions.

1. Go to code::blocks, create a new dll file.
2. Write:
#define GMEXPORT extern "C"  __declspec (dllexport)

GMEXPORT double SampleFunction(double a, double b) {
    return a * b;
(as per @icuurd12b42 's old tutorial) . Build .dll.

3. Go to GMS2, new project, include dll in "Included Files", Room Creation, write:
var my_function = external_define("Test_DLL.dll", "SampleFunction", dll_cdecl, ty_real, 2,ty_real,ty_real);

var a = external_call(my_function,1,2);

"Error defining an external function"

show_debug_message(file_exists("Test_DLL.dll")); returns 1.
Also verified "SampleFunction" existence and parameters.

Same with GMS2's dll template.

So...is this info obsolete? Something I am missing? Do we do things differently in GM:S2?

Edit: GMS2 output also mentions "LoadLibraryA failed with error code 126".
Last edited:


Bros I found a solution.

I installed VC++ runtimes 2017/18/19. It still didn't work and then I went to
Settings->Compiler->Linker settings->Other linker options
and added


It works after this! Probably something I used to know but then forgot since last fiddling with dlls.


TMC Founder
GMC Elder
If you compile with msvc you need the runtime... but if you compiled with msvc and ran the built dll on the same machine, you should not have had the problem because it's installed...

not sure about that static setting; me and a few users discussed this for removing dependencies, where as for me it did not work, but is worked for them.... in msvc the setting is used to force the redist dll code to be part of your dll instead of having the extra dlls as external dependencies........ in codeblocks this was not an option as codeblock did not have a dynamic vs static version for dlls, dll in codeblock would not have a dependency on any other dll, unlike msvc...

Also, careful about debug vs release.... in msvc your debug built dll requires external dependencies specific to helping the msvc ide debug your dll. Definitely do not distribute debug builds

Glad you solved the problem though.