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.

Calling methods from a .DLL ?

Im not sure if this should go here, but here it goes.

I would like to know how i can call methods from a .dll if i make one does it have to be made in a spercific language? C#, C++ etc. Is it possible to call mthods from a .dll created in VB.net?

Well im comftable with all 3 langagues so it doesnt really make a diffrence. i just want to know what i need to do to use methods created in them in a .dll form.

Many thanks :)

EDIT:

Ok i know this involves Win32API, so how can i call it? i just made a test class in C#

Code:
 

namespace DL

{

    public class Initialize

    {

        public static string Add(string hello)

        {

            return (hello);

        }

 

    }

}

 

So if you can help me understand how to call this im sure ill get used to doing this.
 
First you have to get a properly compiled .dll file (as far as I'm aware, language doesn't matter). 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. Seeing the programming languages you know, I feel no need to explain this further. 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.
 
ah thanks, i always seem to get a "GetProcAddress : Add or AddA" error message, any ideas on how to fix that?

heres my Dll Code.

Code:
using System;

using System.Collections.Generic;

using System.Linq;

using System.Text;

 

namespace TestLib

{

    public class TestLib

    {

        public String Add( String hello)

        {

            return hello;

        }

 

    }

}

and my project code.

Code:
module TestLib

    dllcall = Win32API.new("TestLib", "Add", "P", "V")

end

 

class TestDll

   def initialize

    TestLib::dllcall.call("hello")

   end

end

this line gives me an error
Code:
  dllcall = Win32API.new("TestLib", "Add", "P", "V")

"Run time Error occured; GetProcAddress : Add or AddA"

any idea of what im doing wrong :/
 
Cremno":2px51hv8 said:
You're using C# :P
The .NET Framework does not support DLL exports so use C, C++, Delphi, etc..

Or, alternatively, use something to check the method name as it is now, and use that instead. I prefer clean names, though.

In any case, the problem you have is that the method name you are looking for is not the method name you want, since many programming languages will corrupt a method name when compiling a dll file.
 

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