Envision, Create, Share

Welcome to HBGames, a leading amateur game development forum and Discord server. All are welcome, and amongst our ranks you will find experts in their field from all aspects of video game design and development.

C++ Dlls in Ruby

Well I've done small amounts of c++. Well I've seen people make dll's out of c++ and use them in rgss. I want to be able to make these. Now all I've done in c++ is console stuff. So not sure if anyones willing to but can someone help me create my first one?

I wanna be able to alter graphics but simply just give them all a blue hue for starters. Also is it possible to detect input with these dll's? C++ is practically a whole new world to me but I was hoping someone can help me through it. =)
 
For starters, how much C/C++ do you know? The more you know, the better the .dll you can make. As for actually making a .dll file, there are tutorials all over the internet on the subject. Take a look at a few of them, try it out, and if your method names get screwed up, post about it here. As for actually using them in Ruby, here's something I've said a couple of times before, that I really should turn into a tutorial:

Glitchfinder":1br87k0g said:
First you have to get a properly compiled .dll file. Then you'll do the following:

[rgss]dllcall = Win32API.new("dll name", "function name", "LlIiNnPp", "LlIiNnPpVv")
dllcall.call(arg1, arg2...)
[/rgss]

Let me explain.

"dll name": the name of the dll file, with or without the extension. (case insensitive, crashes if not found)
"function name": The name of the function you wish to call. (case sensitive, crashes if not found)
"LlIiNnPp": The arguments. This is a string of characters, which are explained below.
"LlIiNnPpVv": The return value. A single character, follows the same rules as the arguments.

Arguments:
"L" or "l", "N" or "n": A long number. This can be used to pass booleans, where 0 is false and anything else is true.
"I" or "i": An int. This can be used to pass booleans. (see above)
"P" or "p": A pointer to a string. With more advanced programming, can be used to pass other variable types, such as structures.
"V" or "v": Void. May only be used as a return value.

One other thing I would like to note is that if the dll crashes, so will RMXP or RMVX, and that you will receive a non-specific error message regarding the event.
 
I understand how to use them in ruby. I've only messed in console where you can print a string, get a string from user. I really dont know much. I'll search some dll tutorials but I'm not entirely sure how to implement graphic stuff in it. Maybe you could help.

Before that though, I'll start off making my own dll and see if I can do anything special with it.

EDIT: Okay well I didnt know what to do so what I did was this.
File > New > Project > Win32 > Main Project > Chose DLL. Named it Test

Int Test.cpp I have this
Code:
#include "stdafx.h"

 

int Sum(int x, int y)

{

    return x+y;

}

Compiled it successfully.
Ran this code through rmxp
Code:
begin

  dllcall = Win32API.new("Test", "Sum", ['I', 'I'], "I")

  test = dllcall.call(1, 1)

  p test

  exit

end

And like you said no specific error message.
Runtime Error Occured
GetProcAddress Sum or SumA
 
I'm guessing you didn't set it up to export the function. You'll want to make sure to export the functions, so that you can access them in RMXP or RMVX. As for graphics stuff, I can help you if you need to do some bitmap editing. I think you'll find this post to be interesting, as it has an RMXP-compatible source file in it, that I posted. I have since found that lines 11 through 20 and line 52 are not required for the .dll.
 
Your additional bitmap methods helped a ton.

One question if you could please help. Is it possible to draw images directly from c++. Me and a friend plan on having a huge world map. 500x500 tiles to be exact. Maybe not. But when we're done mappnig it, we planned on turning it into an image and letting users view it. With the image so big 16000x16000 to be exact, it'd take forever for ruby to draw it I imagine. So can C++ draw images? I know C++ is a lot faster.

And if needed we'll lower the map size
 

Thank you for viewing

HBGames is a leading amateur video game development forum and Discord server open to all ability levels. Feel free to have a nosey around!

Discord

Join our growing and active Discord server to discuss all aspects of game making in a relaxed environment. Join Us

Content

  • Our Games
  • Games in Development
  • Emoji by Twemoji.
    Top