From: Bill Kelly Date: 2006-01-05T03:18:32+09:00 Subject: Re: Help with the Win32API and DLL interface From: "Beginner" > > I would like to call a Win32API dll from ruby and I did the following: > > > require 'Win32API' > dwtest = "" * 8 > shell1=Win32API.new("my.dll", "myfunc",['P','P','P'],'L') > > myfunc takes 3 parameters, &dwerror, &dwnum, &dwtest. Return value is 0 > or 1. > > > I would like to print or test "&dwtest" which is the 3rd parameter, but > > I don't know what mistake am I doing, it never prints the right value. > I even did "unpack" using dwtest.unpack('L'). [...] > Here is myfunc > > DWORD dwerror > DWORD dwnum > DWORD dwtest > > int myfunc(&dwerror, &dwnum, &dwtest) The DWORD's are passed in as references? Does that mean you are hoping to allow myfunc() to change these values, and see the changes in Ruby? My Win32API experience is quite limited, but I'm not sure if it can handle that. I know that SWIG ( http://www.swig.org/ ) can do it. With SWIG, you would make a "mydll.i" file listing the functions you want to wrap. Something like: ~~~~~~mydll.i~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ %module MYDLL %include "typemaps.i" %{ #include "mydll.h" } typedef long DWORD; int myfunc( DWORD& OUTPUT, DWORD& OUTPUT, DWORD& OUTPUT ); ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ And then run: swig -includeall -ignoremissing -c++ -ruby mydll.i And it will generate Ruby binding code to your mydll functions. Of course, you then have to compile that into a ruby extension library. This is usually done by making an extconf.rb file: ~~~~~~extconf.rb~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ require 'mkmf' create_makefile("mydll") ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ And then running: ruby extconf.rb make # or "nmake" on windows Hmm... Well obviously this is a bit more involved than using Win32API. :-/ Hopefully someone more knowledgeable about Win32API can help you get that working. Regards, Bill