Skip to content

Instantly share code, notes, and snippets.

@nrk
Created September 2, 2008 18:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nrk/8440 to your computer and use it in GitHub Desktop.
Save nrk/8440 to your computer and use it in GitHub Desktop.
Win32API.so ported to IronRuby
irb(main):001:0> require 'Win32API'
=> true
irb(main):002:0> $get_logical_drives = Win32API.new('kernel32', 'GetLogicalDriveStrings', ['P', 'P'], 'I')
=> #<Win32API:0x2e2a200>
irb(main):003:0> $buffer = ' ' * 32
=> " "
irb(main):004:0> $length = $get_logical_drives.call($buffer.length, $buffer)
=> 16
irb(main):005:0> $buffer
=> "A:\\\000C:\\\000D:\\\000S:\\\000\000 "
irb(main):006:0> $buffer[0..$length].split(0.chr)
=> ["A:\\", "C:\\", "D:\\", "S:\\"]
irb(main):007:0>
IronRuby 1.0.0.0 on .NET 2.0.50727.1433
Copyright (c) Microsoft Corporation. All rights reserved.
Note that local variables do not work today in the console.
As a workaround, use globals instead (eg $x = 42 instead of x = 42).
>>> require 'Win32API'
=> true
>>> $get_logical_drives = Win32API.new('kernel32', 'GetLogicalDriveStrings', ['P', 'P'], 'I')
=> #<Win32API:0x000005c>
>>> $buffer = ' ' * 32
=> " "
>>> $length = $get_logical_drives.call($buffer.length, $buffer)
=> 16
>>> $buffer
=> "A:\\\000C:\\\000D:\\\000S:\\\000\000 "
>>> $buffer[0..$length].split(0.chr)
=> ["A:\\", "C:\\", "D:\\", "S:\\"]
>>>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment