Windows DLL Implementation

Drell

Member
I am currently implementing a 3rd party DLL in my sudio's game, Evolver, and I'm having some issues understanding how the DLL would work in game maker. The DLL is a netcode that uses an object to manage the game session between end users, and I know that part of the issue is my lack of C based knowledge. This is the bit of example code that establishes the session to be managed:



GGPOSession is a struct containing GGPOSession. Then, GGPOErrorCode is the object name in the DLL itself, and ggpo_start_session is used to initialize the object. What I don't understand is how the variables are passed in and out of the DLL objects. I copied the example into GML as best I could:



but the immediately visible issue is the DLL reference variables will simple be treated as GML variables and either throw an error or have no effect at all. So, how do I get the Game Maker to pass, for example, the GML variable "result" to the DLL's variable GGPOErrorCode where GGPOErrorCode is an object? I am/was thinking this could be done using the extension constants, but the manual isn't exactly clear on how GM:S handles the value implemented. All help is much appreciated as this is crucial to my final project!
 
The simplest ( and as far as I'm aware the only ) way to do this is to have separate functions in your DLL that take some value as input and save it into some variable that you handle from your C code. This also works the other way, you can add a getter function to your DLL that queries some C variable and returns it to GM. However, this is a bit constrained because you can only really pass strings and doubles between the DLL and GM.

Here's a very simple example:
Code:
#include <stdio.h>

static int foo;

double set_foo(double v) {
    foo = (int)v;
    
    // Afaik you can't have functions without a return value, but I might be wrong on that
    return 1.0;
}

double get_foo() {
    return foo;
}

double print_foo() {
    printf("Foo: %d\n", foo);
    return 1.0;
}
You can call these functions from GM to manipulate foo's value. As I see you have structs; unfortunately, for that you would need separate setter/getters for each member ( or just one setter that sets all member variables and be done with it ).

I also suspect you want to be able to pass GML scripts as callbacks to the DLL. This is not exactly doable this way. What you can do instead is to put all these events in a queue on C side, "attach" scripts to event types in GML, regularly pull all the events from the C queue from GML and call the scripts yourself. I hope I was able to explain the latter concept, but I can whip up a simple example if needed.
 
R

rui.rosario

Guest
you can use buffers to return whatever data you want from the dll. If that dll is written in c code then i can help you once i get home, just shoot me a pm if you want.
 
Top