Forum: Ruby win32api: i probably don't understand pointer packing...

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
0ac9ec73f8186f7f18f203e3620278d8?d=identicon&s=25 cies (Guest)
on 2007-03-31 16:07
(Received via mailing list)
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/fid51853E4D2B2777DF792D2B2...

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!
This topic is locked and can not be replied to.