Skip to content

Instantly share code, notes, and snippets.

@vvs
Created January 6, 2010 09:27
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 vvs/270159 to your computer and use it in GitHub Desktop.
Save vvs/270159 to your computer and use it in GitHub Desktop.
require 'ffi'
module MyFFI
FORMAT_MESSAGE_FROM_SYSTEM = 0x00001000
extend FFI::Library
ffi_lib 'kernel32'
ffi_convention :stdcall
attach_function :FormatMessageA, [:int, :pointer, :int, :int, :string, :int, :pointer], :int
end
msg = " " * 1024
p len = MyFFI.FormatMessageA(MyFFI::FORMAT_MESSAGE_FROM_SYSTEM, nil, 6, 0, msg, 1024, nil)
p msg[0..len-3] # remove \r\n\000
D:\work\jruby-dev\samples\FFI>jruby formatMessage.rb
24
" "
D:\work\jruby-dev\samples\FFI>ruby -rrubygems formatMessage.rb
24
"The handle is invalid."
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment