Win32API

Started by Blizzard, April 25, 2011, 01:38:55 pm

Previous topic - Next topic

Blizzard

I have come across an interesting problem. It seems that the module Win32API is not naturally supported by Ruby and that for some reason I can't get it properly running like a Ruby script. #_#
Does anybody have an idea what we can do about this? As far as I can tell, RMXP's Game.exe does only have the RTP hidden scripts integrated but not any code mentioning Win32API.

We can't finish ARC and allow loading of external stuff if we can't find a solution for this problem.
Check out Daygames and our games:

King of Booze 2      King of Booze: Never Ever
Drinking Game for Android      Never have I ever for Android
Drinking Game for iOS      Never have I ever for iOS


Quote from: winkioI do not speak to bricks, either as individuals or in wall form.

Quote from: Barney StinsonWhen I get sad, I stop being sad and be awesome instead. True story.

Ryex

April 25, 2011, 03:19:50 pm #1 Last Edit: April 25, 2011, 03:45:08 pm by Ryex
the win32api allows ruby to load dlls and make calls to their exported functions right? is there any way to "simulate" the effect ourselves?
I no longer keep up with posts in the forum very well. If you have a question or comment, about my work, or in general I welcome PM's. if you make a post in one of my threads and I don't reply with in a day or two feel free to PM me and point it out to me.<br /><br />DropBox, the best free file syncing service there is.<br />

Blizzard

Yes and no. As far as I have noticed, Ruby does have a Win32API script, but it requires some other components. I've tried including all scripts, but in the end it seems that an additional .so file (dl.so) is required. :/ I'm not sure, but that one should have been compiled into the Ruby DLL. I guess I will have to recompile Ruby later again to make a minimalistic build or something.

In any case, it would be good to know how Enterbrain did it or if there is an alternative.
Check out Daygames and our games:

King of Booze 2      King of Booze: Never Ever
Drinking Game for Android      Never have I ever for Android
Drinking Game for iOS      Never have I ever for iOS


Quote from: winkioI do not speak to bricks, either as individuals or in wall form.

Quote from: Barney StinsonWhen I get sad, I stop being sad and be awesome instead. True story.

ForeverZer0

I ran into the same problem before when trying to create a WINOLE extension for RMXP. I eventually just gave up on it. On another note, how exactly will the Win32API library behave on non-windows systems?
I am done scripting for RMXP. I will likely not offer support for even my own scripts anymore, but feel free to ask on the forum, there are plenty of other talented scripters that can help you.

Blizzard

Not at all? ._.;;;
I have no idea. I guess we should just make sure that C functions can be called. That's all we need, really. I'd actually prefer if we call it DllApi or OsApi. We can alias that class into Win32API on Windows platforms, that's not a problem.
Check out Daygames and our games:

King of Booze 2      King of Booze: Never Ever
Drinking Game for Android      Never have I ever for Android
Drinking Game for iOS      Never have I ever for iOS


Quote from: winkioI do not speak to bricks, either as individuals or in wall form.

Quote from: Barney StinsonWhen I get sad, I stop being sad and be awesome instead. True story.

Cremno

April 26, 2011, 07:02:07 am #5 Last Edit: April 26, 2011, 07:03:35 am by CremnoIsNotABot
Hello guys,

I would appreciate it if you use win32-api instead of the old and crappy Win32API. It's from the same guy and a great successor. The Win32API version in the current Ruby versions isn't.
Either you compile the api.c from the win32-api sources into one of your DLLs or distribute it as SO/DLL. Because of the lack of the (Ruby) header and libs it was a bit time-consuming (distribute them too so users can compile their own extensions!) but I managed to build one: http://cremno.bplaced.net/tmp/api.so

If you download it into Data you can use following code:
require_relative 'api'
include Win32
hwnd = API.new('GetForegroundWindow', 'V', 'L', 'user32').call
mb = API.new 'MessageBox', 'LSSI', 'I', 'user32'
mb.call hwnd, RUBY_DESCRIPTION, 'ARC - win32-api test', 0



And sorry about my username - your spam protection didn't like me  :<_<:

G_G

Seems interesting, I'm sure it doesn't but does work on other OS's other than windows?

Cremno

No, of course it doesn't work. If you want to have a multi-platform possibility to call dynamic library functions then use Ruby FFI. It's more complex and heavily differs from Win32API and win32-api. Take a look the wiki for more information!

Btw, on Win32 platforms you could provide a Win32API wrapper based on Ruby FFI so it doesn't break compatibility with existing RGSS scripts.

Blizzard

April 26, 2011, 02:08:43 pm #8 Last Edit: April 26, 2011, 03:00:05 pm by Blizzard
Thanks for the heads-up. I successfully incorporated your api.so for testing. What did you use to compile it? VS2005, VS2008, VS2010 or MinGW?

I'll try to include Win32::API the next time I try to compile a minimalistic Ruby DLL. It seems that this time it was included (which is unusual as it's part of Ruby's SL).

BTW, I can change your username (not just the display name) if you want. Just tell me which you want.

EDIT: Ah, crap. :/ It looks like I will have to figure out something else. Combining Win32::API and interfacing it with a dummy Win32API class with actual Win32API calls in RMXP scripts causes the render window to act weird. It seems that the window still renders, but there is no response to Windows whatsoever. In fact, Windows perceives the render window to not be responding at all. O_o I guess I'll have to compile Ruby with the Win32API class integrated either way.
Check out Daygames and our games:

King of Booze 2      King of Booze: Never Ever
Drinking Game for Android      Never have I ever for Android
Drinking Game for iOS      Never have I ever for iOS


Quote from: winkioI do not speak to bricks, either as individuals or in wall form.

Quote from: Barney StinsonWhen I get sad, I stop being sad and be awesome instead. True story.

Cremno

April 26, 2011, 03:04:04 pm #9 Last Edit: April 26, 2011, 03:06:28 pm by CremnoIsNotABot
I used VS2010 because you've also used it to compile the Ruby interpreter. If you include it then don't forget to read the license..

And just to make sure: the RGSS-Win32API is not the same as Ruby 1.9 ones. The original is written in C and was compiled into the RGSS-DLL (not Game.exe). The other one is based on DL and written in Ruby.
If I remember right you can compile DL and Win32API into your Ruby-DLL (msvcr100-ruby191.dll) when you remove the Sharp (#) in front of them in the \ext\Setup file. But as I already said Win32::API is the better choice!


It would be great when you change my name into Cremno.


Edit: I wrote this before I read your edit.

Blizzard

April 26, 2011, 03:11:27 pm #10 Last Edit: April 26, 2011, 03:14:23 pm by Blizzard
I am convinced that Win32::API is the better choice, but for the RGSS portion of the engine we'll have to go with plain old Win32API.

Quote from: Cremno on April 26, 2011, 03:04:04 pm
If I remember right you can compile DL and Win32API into your Ruby-DLL (msvcr100-ruby191.dll) when you remove the Sharp (#) in front of them in the \ext\Setup file. But as I already said Win32::API is the better choice!


This is exactly the info I was looking for. I forgot most of it since I compiled Ruby 2 months ago.

Quote from: Cremno on April 26, 2011, 03:04:04 pm
It would be great when you change my name into Cremno.


Done. Both your display name and your username are now Cremno.

I'll be sure to include you in the ARC credits. You probably saved me hours of research and headache with this info. xD Do you want to be credited only as Cremno or with your real name as well?

EDIT: Do you know by any chance which options allow me to compile a minimalistic Ruby? Enterbrain's RGSSXXXX.dll is only about 700 kB while the msvcr100-ruby191.dll that I compile is already over 1.1 MB just by itself. I'm sure Enterbrain removed some Ruby features to make the RGSS DLL smaller.
Check out Daygames and our games:

King of Booze 2      King of Booze: Never Ever
Drinking Game for Android      Never have I ever for Android
Drinking Game for iOS      Never have I ever for iOS


Quote from: winkioI do not speak to bricks, either as individuals or in wall form.

Quote from: Barney StinsonWhen I get sad, I stop being sad and be awesome instead. True story.

Cremno

April 26, 2011, 03:23:06 pm #11 Last Edit: April 26, 2011, 03:32:38 pm by Cremno
Thank you but I just tested it and it doesn't compile. It gives me fatal error:
QuoteNMAKE : fatal error U1073: don't know how to make '/include/ruby/ruby.h'

When I first compiled Ruby it worked but that was some Ruby 1.8 version. Ruby on Windows is a pain in the ass but I'll take a look into it.

If you are going to mention me in the credits you can use my nick name.

Edit: Don't forget that you're using Ruby 1.9.2! Enterbrain's DLL uses Ruby 1.8.1 and therefore it misses much features. It's also packed (and crypted). Unpacked it's about 1.5 MB. Another reason for the "small" size is that the RGSS itself uses much Win API calls so code for rendering and bitmap manipulation is provided by Windows and not by self written DLLs.

Blizzard

Yeah, compiling Ruby is nasty. There was a good step-by-step guide I once found somewhere, but I have no idea where it was. I think it was in README.win32, but I can't find it there anymore. >.<
Check out Daygames and our games:

King of Booze 2      King of Booze: Never Ever
Drinking Game for Android      Never have I ever for Android
Drinking Game for iOS      Never have I ever for iOS


Quote from: winkioI do not speak to bricks, either as individuals or in wall form.

Quote from: Barney StinsonWhen I get sad, I stop being sad and be awesome instead. True story.

Ryex

progress? I'm seeing activity form you in my email :P
I no longer keep up with posts in the forum very well. If you have a question or comment, about my work, or in general I welcome PM's. if you make a post in one of my threads and I don't reply with in a day or two feel free to PM me and point it out to me.<br /><br />DropBox, the best free file syncing service there is.<br />

Blizzard

Lol, you stalker. xD
Actually yes. I just got everything running a couple of minutes ago. I am using the new Win32API (even though the old one would have actually worked as well since the window-freezing was caused by something else) and I have written a small wrapper for compatibility. We will leave that wrapper with the RMXP compatibility code later.

After literally days of accumulated work I finally figured it out. This was one of the nastiest programming problems I have solved in my entire life. In the end it wasn't all too complicated, but without having anybody to point me in the right direction, I had to do trial-and-error until I found a solution.
Check out Daygames and our games:

King of Booze 2      King of Booze: Never Ever
Drinking Game for Android      Never have I ever for Android
Drinking Game for iOS      Never have I ever for iOS


Quote from: winkioI do not speak to bricks, either as individuals or in wall form.

Quote from: Barney StinsonWhen I get sad, I stop being sad and be awesome instead. True story.