Win32API question/suggestion

D

Daniel Berger

Hi all,

As I sit here finally learning the Win32API module, rather than
writing C extensions, I was wondering about something...

There are many generic functions used in Win32 programming, such as
GlobalAlloc(), GlobalFree(), etc. Currently, it appears that I have
to do this:

GlobalAlloc = Win32API.new(...)
GlobalAlloc.Call

The problem with this is that it means I have to redefine these in
separate packages every time I want to use them. Would it be possible
to alter the Win32API module so that I could just do:

Win32API.GlobalAlloc(...)

Thus, the class method names would correspond to the equivalent Win32
API call. After all, the method signatures don't change, so making me
do it longhand every time feels annoying. Having the relevant
constants predefined and available (GMEM_MOVEABLE, etc, etc) would be
nice, too.

This would make things easier and wouldn't break backwards
compatibility (since it would just be a matter of adding class methods
to the Win32API package). I realize that I could add these methods
easily enough myself, but wouldn't it be nice if everyone had these
ready to go?

Thoughts? Opinions? It can already do this and I missed the boat
somewhere?

Regards,

Dan
 
S

Shashank Date

Thoughts? Opinions? It can already do this and I missed the boat
somewhere?

I have thought about this myself, but never seriously pursued it. I think
it is a very good idea and that it is currently not there. I am willing to
devote my time on this project if we decide to go ahead with it.
Regards,

Dan

Thanks, Dan, and a very Happy New Year to you.
-- shanko
 
D

daz

Daniel said:
Hi all,

As I sit here finally learning the Win32API module, rather than
writing C extensions, I was wondering about something...

There are many generic functions used in Win32 programming, such as
GlobalAlloc(), GlobalFree(), etc. Currently, it appears that I have
to do this:

GlobalAlloc = Win32API.new(...)
GlobalAlloc.Call
[...]
Thoughts? Opinions? It can already do this and I missed the boat
somewhere?

Moonwolf has drawn together much of this in:
http://www.moonwolf.com/ruby/archive/win32module_20001226b.tar.bz2 (537Kb)


If you can't extract bz2 files, try:
http://www.7-zip.com/
(There may be better ones)

copy contents of win32 dir to ---\lib\ruby\1.8\win32, then
require 'win32/winbase' ## loads Win32API itself
GlobalAlloc.call(...)



daz
 
D

daz

I said:
copy contents of win32 dir to ---\lib\ruby\1.8\win32 ## [WRONG]

Correction - sorry. \lib\ruby\site_ruby\1.8\win32

This is important because registry.rb in the standard distribution
would be overwritten.

As site_ruby takes precedence, the win32module version of
registry.rb should *_not_* be included in the copy.


Happy New Year to all,


daz
 
D

Daniel Berger

daz said:
I said:
copy contents of win32 dir to ---\lib\ruby\1.8\win32 ## [WRONG]

Correction - sorry. \lib\ruby\site_ruby\1.8\win32

This is important because registry.rb in the standard distribution
would be overwritten.

As site_ruby takes precedence, the win32module version of
registry.rb should *_not_* be included in the copy.


Happy New Year to all,


daz

Thanks daz. I played around with it some. There are two problems I
have with it. First, serious lack of documentation. Second, I don't
like having methods and constants slapped into my namespace by
sticking all the methods in a module instead of a class.

However, he's obviously put a lot of work into this and a pretty
healthy chunk of the methods and constants are defined. I suppose I
can copy & paste and write the API the way I like it. :)

Regards,

Dan
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Members online

No members online now.

Forum statistics

Threads
473,764
Messages
2,569,567
Members
45,041
Latest member
RomeoFarnh

Latest Threads

Top