Win32api: i probably don't understand pointer packing


hi all,

i’m trying to sent some simple midi messages to a midi device on a
windows machine, therefor i try to use Win32API.

but i guess i don’t understand the packing of pointers well enough, it
keeps returning an “invalid parameter passed” error code. i tried many

a little help would be very welcome!
maybe i take the complete wrong approach… please let me know if you
think i do.

you can see the full file in the attachment, or an excerpt here:

require ‘Win32API’

#reference of winmm.dll’s midi API for “midiOutOpen”:

#mmsystem.h (from wine):

class Win32MidiOut

some constants from (wine’s) mmsystem.h

CALLBACK_NULL = 0x00000001
0 => ‘no error’,
1 => ‘unspecified error’,
2 => ‘device ID out of range’,
3 => ‘driver failed to enable’,
4 => ‘device already allocated’,
5 => ‘device handle invalid’,
6 => ‘no device driver present’,
7 => ‘memory allocation error’,
8 => ‘function isn’t supported’,
9 => ‘error value out of range’,
10 => ‘invalid flag passed’,
11 => ‘invalid parameter passed’

def self.device_count“winmm”, “midiOutGetNumDevs”, [], ‘I’).call

def open_device(num)
f =“winmm”, “midiOutOpen”, ‘PPPPI’, ‘I’)
id_ptr = [num].pack(‘I’)
callback_prt = [0].pack(‘l’)
callback_instance_prt = [0].pack(‘l’)
err =, id_ptr, callback_prt, callback_instance_prt,
puts ERR_MSG[err]
p @device

p Win32MidiOut::device_count