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":
#http://msdn2.microsoft.com/en-us/library/ms711632.aspx

#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!

Win32MidiOut.rb (8.52 KB)

ยทยทยท

--
"Computer games don't affect kids; I mean if Pac-Man affected us as
kids, we'd all be running around in darkened rooms, munching magic
pills and listening to repetitive electronic music." -- Kristian
Wilson (Nintendo, Inc), 1989