Using DL instead of Win32API.

Hey there..

Recently I was looking into using the DL class directly for performing my dll calls; however, I am not fully sure on how to implement a 'switch' from my current Win32AI functions.

For example, lets say I have a dll called 'DekitaAwesomeDLL' and within it, a function named 'RandomFunction' which accepts a pointer, a long int and a regular int. This function also returns an int.

I could use Win32API like so...

function = Win32API.new('DekitasAwesomeDLL','RandomFunction','PLI','I') # Assumes 'pointer,longint,regint' are already defined. function.call(pointer,longint,regint)I am not sure on how to convert such a call into the DL class directly.  I think* it would be something like this...

dll = DL::dlopen('DekitasAwesomeDLL') function = DL::CFunc.new(dll, DL::TYPE_INT, 'RandomFunction', :stdcall) # Assumes 'pointer,longint,regint' are already defined. function.call(pointer,longint,regint)But I am not sure on how the actual pointer, longint and regint should differ hen using DL compared to Win32API.

Anyone able to provide info on this ? 🙂
Figured I would post my findings here in case anyone else is trying to figure out how to do this and stumbles across this topic....

Example Win32API Code:

module DLTEST def self.call_api Win32API.new('user32','keybd_event','iill','').call(0x71,0,0,0) end endExample DL Code: (does the same as the above Win32API code)

module DLTEST def self.call_api @dll ||= DL::dlopen('user32') @name ||= 'keybd_event' @type ||= DL::TYPE_VOID @call ||= :stdcall @func ||= DL::CFunc.new(@dll[@name], @type, @name, @call) @func.call([0x71,0,0,0]) end endFor quickly checking it works... Grab any of the above definitions of 'call_api' and then add this snippet, then when on the title screen, press left or right and it will trigger the 'F2' key (to show FPS).

class Scene_Title < Scene_Base def update if [:LEFT,:RIGHT].any? { |key| Input.trigger?(key) } DLTEST.call_api end super end endTheres probably a lot more to it, but that should be enough to get folks going. ^_^
Is there any advantage to using DL over Win32API?
Faster. It essentially cuts out the middleman. 😀

Win32API uses DL, and is deemed obsolete from ruby 2.x+  🙂

Only problems I've been having is when trying to send a pointer to a long int dword or whatever.  (the documentation i have is somewhat contradictory on what the call is expecting) ~ Probably something newbish im missing ~ not been paying much attention to C recently, so i havent really been gaining C code skills 😀
Looks cool! Can you share the documentation you have?

Oh, and why is the type DL::TYPE_VOID?
The function is not returning any value, Win32API.new('user32','keybd_event','iill','') <-- last argument
I found another way to use the DL: http://www.rpg-studio.org/scientia/Ruby/DL

@zeriab

Oh, of course! I thought it was something else.
@khas ~ What documentation? I have been using information found online and in the ruby docs regarding using the DL class. Had to piece a lot of it together still 😛

And naturally, RPG Maker has removed about half of the DL class functions, like .value.. 🙂
@dekita

When you said something about "the documentation you have" I got curious hahah

I did some search and the information is quite fragmented and somewhat poor
Ahh yea I see now ^_^

The documentation I was referencing was some MSDN docs. it said it was expecting a pointer to an unsigned long int DWORD, this confused me.  Ive since found out that an unsigned long int is a DWORD 😛

But yea, the documentation for the use of Win32API vs DL is fairly scarce 🙁

Original thread: https://forums.rpgmakerweb.com/threads/using-dl-instead-of-win32api.36882/