The Artima Developer Community
Sponsored Link

Ruby Buzz Forum
Revamping Win32API

0 replies on 1 page.

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 0 replies on 1 page
Daniel Berger

Posts: 1383
Nickname: djberg96
Registered: Sep, 2004

Daniel Berger is a Ruby Programmer who also dabbles in C and Perl
Revamping Win32API Posted: Jul 13, 2006 8:41 PM
Reply to this message Reply

This post originated from an RSS feed registered with Ruby Buzz by Daniel Berger.
Original Post: Revamping Win32API
Feed Title: Testing 1,2,3...
Feed URL: http://djberg96.livejournal.com/data/rss
Feed Description: A blog on Ruby and other stuff.
Latest Ruby Buzz Posts
Latest Ruby Buzz Posts by Daniel Berger
Latest Posts From Testing 1,2,3...

Advertisement
In the CVS repo for the Win32 Utils project you'll find a project called "windows-api". It's my attempt to cleanup and revamp the Win32API package. The first iteration didn't do much more than some basic code cleanup and add instance variables for various bits of information that were previously unreachable.

Certain things still bothered me, though. The sorts of things that only start to bother you after prolonged, heavy use. First, I've realized that the majority of the functions that I define are coming from kernel32, yet there's no way to set a default library. Second, about half the functions return BOOL, with the rest returning some form of long (usually a HANDLE), or are void functions, yet there's no way to set a default return value. Lastly, the idiom of assigning the function name to a constant of the same name one call at a time is very tedious. I've decided that I want something that will automatically create that constant for me.

My second iteration dealt with two of these issues. So now the interface looks like this:
Function = Windows::API.new('Function', prototype='V', return='I', dll='kernel32')

That's better than what we've got currently, but it still means manually assigning constants, one method call at a time, not to mention manually defining an equivalent method:
def Function(arg1, arg2, ...)
   Function.call(arg1, arg2, ...)
end

I've been kinda mulling over what a better interface might look like. Perhaps it was fate that I stumbled across Win32-API-Interface today. I think Sascha has some good ideas. Using her API for ideas, now I'm thinking of adding something like this:
module Foo
   Windows::API.create do
      :kernel32 => [
         ['GetTempPath', 'LP', 'N' ],
         ['GetCurrentProcessId', 'V', 'L', 'get_pid']
      ],
      :user32 => [
        ['GetCursorPos', 'P', 'I']
      ],
   end
end

# and later...
include Foo

path = GetTempPath(arg1, arg2)
pid  = get_pid

This adds one extra clever bit as well. The last array argument would be an auto generated alias that would be exported instead of (or in addition to) the normal constant.

Now, to get cracking...

Read: Revamping Win32API

Topic: Uh Oh, Someone Saw the Smoke Previous Topic   Next Topic Topic: Methods That Self-Destruct

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use