Problems With DirectSound & DL


#1
Hello Everyone,
    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. 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("
 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.