# Win32api: i probably don't understand pointer packing

**URL:** <https://www.ruby-forum.com/t/win32api-i-probably-dont-understand-pointer-packing/90731>\
**Category:** Ruby\
**Created:** [March 31, 2007, 4:07pm UTC](https://www.ruby-forum.com/t/win32api-i-probably-dont-understand-pointer-packing/90731 "2007-03-31T16:07:27Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![cies](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/e0b2c6/32.png) [@cies](https://www.ruby-forum.com/u/cies)\
**Post date:** [March 31, 2007, 4:07pm UTC](https://www.ruby-forum.com/t/win32api-i-probably-dont-understand-pointer-packing/90731/1 "2007-03-31T16:07:27Z")

</div>

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

#mmsystem.h (from wine):  
#[http://www.koders.com/c/fid51853E4D2B2777DF792D2B246103C7C446CF3B67.aspx](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!
