# Problems With DirectSound & DL

**URL:** <https://www.ruby-forum.com/t/problems-with-directsound-dl/108315>\
**Category:** Ruby\
**Created:** [July 2, 2007, 5:42am UTC](https://www.ruby-forum.com/t/problems-with-directsound-dl/108315 "2007-07-02T05:42:45Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![pdubb](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/e0b2c6/32.png) [@pdubb](https://www.ruby-forum.com/u/pdubb)\
**Post date:** [July 2, 2007, 5:42am UTC](https://www.ruby-forum.com/t/problems-with-directsound-dl/108315/1 "2007-07-02T05:42:45Z")

</div>

Hello Everyone,  
&nbsp;&nbsp;&nbsp; I'm trying to make an MP3 player in Ruby. I would like to make it in pure Ruby, but I've come to the conclusion that Ruby is too high level to mess around with sound buffers and such. So I'm making the MP3 player in Ruby, and using DL and dsound.dll to access the DirectSound API. But I'm having trouble invoking IDirectSound8::SetCooperativeLevel as mentioned on [this page](http://msdn2.microsoft.com/en-us/library/bb206041.aspx). I've tried every way I could think of to try to get it to run, but with no success. Below is the Ruby code that I have so far. I know its messy, and I'm planning to do a rewrite of it before I distribute it. Right now I'm just trying to learn how to accomplish invoking the DLL.  
  
The code:  
  
require 'dl'  
require 'dl/import'  
require 'pp'  
hello\_me = DL.malloc(DL.sizeof('P'))  
hwnd = DL.malloc(DL.sizeof('P'))  
dsound = DL.dlopen('dsound')  
soundobject1 = dsound['DirectSoundCreate8', 'LSPS']  
pp soundobject1.call(nil, hello\_me, nil)  
pp hello\_me  
module Blah  
extend DL::Importable  
def self.setCooperativeLevel(ptr, appwindow=0, priority='ii')  
coopthing = String.new  
coopthing += "#{ptr.to\_ptr}"  
coopthing += "-\>SetCooperativeLevel("  
&nbsp;if appwindow == 0 then  
coopthing += "hwnd"  
else  
coopthing += appwindow  
end  
if priority == 'ii' then  
coopthing += ", DSSCL\_PRIORITY)"  
else  
coopthing += ", " + priority + ")"  
end  
pp coopthing  
extern "#{coopthing}"  
end  
end  
pp Blah.setCooperativeLevel(hello\_me)  
  
I'm running Windows XP Professional.  
  
Thanks,  
Philip W.
