Building a DLL File to use in Scripts!

Making a custom DLL file for use in your games isnt as hard as it sounds!  Im sure lots of people, once they get used to programming in Ruby want to go to the next step and working with compiled languages.  That is pretty much where I am at right now.


So here are the basics!


C++ "Header.h" File:


#pragma once

#define DLLEXPORT __declspec(dllexport)

extern "C" __declspec (dllexport) int hello(int);


C++ "Source.cpp" File:


#include "Header.h"

int hello(int arg)
{
arg--;
return arg;
}




Once the program is compileled, put the DLL file in your RPG Maker Game Directory.


And finally, Ruby Code: (Im using XP, not sure if different on VX or Ace)


class Game_Character
# Win32 API, (File, Method, Input Type, Output Type)
# Types are I for Int, L for Long, P for Pointer, and V for Void
# Can also use Empty Quotes
Hello = Win32API.new("RMDLL.dll", "hello", "I", "I")

def hello(arg)
print Hello.call(arg)
end
end




Finally, any Character can use the DLL file to process the data.


$game_player.hello(5)  # Prints 4 in this case


Thems are the most basic basics.  The above code is completely useless, but, with some more experience, you can do very complex things such as create your own Move Routes or Bitmap Manipulations!  If your package is good enough, it may even benefit a commercial game.  My intent here is for non commercial purposes, but also depends on what we do with our custom DLL Files!


There is so much more that can be done with DLL files.  Does anyone want to add to this in order to help people do things with DLL files that are more useful?  Perhaps expanding on the idea of using Pointers with C++ / C# and Ruby?


(Note for Moderators: I asked Andar where I should post this.  He advised he will discuss this with the rest of the staff where programming that is more specific to C++ and other compiled languages are best posted in the forum, so feel free to place this post where it is most appropriate, and edit this post as needed.)

Original thread: https://forums.rpgmakerweb.com/threads/building-a-dll-file-to-use-in-scripts.63238/