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
combinations.

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”:
#midiOutOpen | Microsoft Learn

#mmsystem.h (from wine):
#http://www.koders.com/c/fid51853E4D2B2777DF792D2B246103C7C446CF3B67.aspx

class Win32MidiOut

some constants from (wine’s) mmsystem.h

CALLBACK_NULL = 0x00000001
ERR_MSG = {
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
Win32API.new(“winmm”, “midiOutGetNumDevs”, [], ‘I’).call
end

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

p Win32MidiOut::device_count
p Win32MidiOut.new.open_device(0)

#thanks!