This post originated from an RSS feed registered with Ruby Buzz
by Daniel Berger.
Original Post: win32-api and function pointers
Feed Title: Testing 1,2,3...
Feed URL: http://djberg96.livejournal.com/data/rss
Feed Description: A blog on Ruby and other stuff.
It wasn't very long into the win32-ole rewrite that we discovered we need to be able to wrap a raw function pointer (address) via win32-api if we wanted to continue. It was easy enough to add. So, now, with the release of 1.1.0, you can do this:
require 'win32/api'
include Win32
LoadLibrary = API.new('LoadLibrary', 'P', 'L')
GetProcAddress = API.new('GetProcAddress', 'LP', 'L')
hlib = LoadLibrary.call('user32')
addr = GetProcAddress.call(hlib, 'MessageBeep')
func = Win32::API::Function.new(addr, 'L', 'L') # This is the new bit
func.call(0)
The original motivation came from the GetActiveObject() function which takes and returns a pointer to an active object. Since that only gives us an address and not a name, we had to be able to deal with that.