Forum: Ruby Problems With DirectSound & DL

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.
E7857490edd140c561cb56570565efc9?d=identicon&s=25 Philip W. (Guest)
on 2007-07-02 05:42
(Received via mailing list)
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
  <meta content="text/html;charset=ISO-8859-1"
http-equiv="Content-Type">
  <title></title>
</head>
<body bgcolor="#ffffff" text="#000000">
Hello Everyone,<br>
&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 <a
 href="http://msdn2.microsoft.com/en-us/library/bb206041....
page</a>.
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.<br>
<br>
The code:<br>
<br>
require 'dl'<br>
require 'dl/import'<br>
require 'pp'<br>
hello_me = DL.malloc(DL.sizeof('P'))<br>
hwnd = DL.malloc(DL.sizeof('P'))<br>
dsound = DL.dlopen('dsound')<br>
soundobject1 = dsound['DirectSoundCreate8', 'LSPS']<br>
pp soundobject1.call(nil, hello_me, nil)<br>
pp hello_me<br>
module Blah<br>
extend DL::Importable<br>
def self.setCooperativeLevel(ptr, appwindow=0, priority='ii')<br>
coopthing = String.new<br>
coopthing += "#{ptr.to_ptr}"<br>
coopthing += "-&gt;SetCooperativeLevel("<br>
&nbsp;if appwindow == 0 then<br>
coopthing += "hwnd"<br>
else<br>
coopthing += appwindow<br>
end<br>
if priority == 'ii' then<br>
coopthing += ", DSSCL_PRIORITY)"<br>
else<br>
coopthing += ", " + priority + ")"<br>
end<br>
pp coopthing<br>
extern "#{coopthing}"<br>
end<br>
end<br>
pp Blah.setCooperativeLevel(hello_me)<br>
<br>
I'm running Windows XP Professional.<br>
<br>
Thanks,<br>
Philip W.<br>
</body>
</html>
This topic is locked and can not be replied to.