Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

.DLL and DirectSound

649 views
Skip to first unread message

Michael Chase

unread,
May 13, 2002, 4:24:01 PM5/13/02
to
Is it possible to use Direct Sound in a background thread
without an associated window. E.g., play DirectSound
from a Windows Service or DLL? If you try using
the .Play() interface, it returns DSERR_PRIOLEVELNEEDED.

I've see a lot of posts stating that the DirectX audio
sub-system expects an app to have a window ( *with* the
current focus ) before it will play any sound? Yikes!

Is the design this dainbrammaged? I hope I'm missing
something VERY OBVIOUS.

Michael

Philip Taylor [ MS ]

unread,
May 13, 2002, 4:41:55 PM5/13/02
to
no, a window handle is needed.

it can be an invisible window.

--

Phil Taylor
PM : DirectX SDK, Managed DirectX, Windows XP Inbox 3D screensavers, and a
few more bits and bobs.
http://msdn.microsoft.com/directx
This posting is provided "AS IS" with no warranties, and confers no rights.
"Michael Chase" <cha...@comtrix.com> wrote in message
news:2ed901c1fabc$1ea17d20$39ef2ecf@TKMSFTNGXA08...

Michael Chase

unread,
May 13, 2002, 6:49:39 PM5/13/02
to
Is it true that the window *must* have the focus in order
for Direct Sound to play ? If so, how do you give an
invisible window the focus with out confusing the other
normal desktop apps, and the user?

I guess the question is: What is the best way to play a
sound with out the window ( visible or invisible ) focus
issue? I really don't want the app that created the
window ( invisible or otherwise ) to have to take the
focus from other foreground apps.

And thank you, Phil ( Microsoft ), for your swift answers.

Michael

>.
>

Philip Taylor [ MS ]

unread,
May 13, 2002, 7:57:01 PM5/13/02
to
the window handle exists, even if the window is invisible.

this is necessary because DirectX subclasses the window procedure to perform
certain tasks on certain Windows events.

as far as having the focus, that could be a problem, some experimentation is
likely needed. Remember that services were added after DirectX.

--

Phil Taylor
PM : DirectX SDK, Managed DirectX, Windows XP Inbox 3D screensavers, and a
few more bits and bobs.
http://msdn.microsoft.com/directx
This posting is provided "AS IS" with no warranties, and confers no rights.
"Michael Chase" <cha...@comtrix.com> wrote in message

news:331901c1fad0$768e3fa0$3bef2ecf@TKMSFTNGXA10...

Alan Ludwig [MS] [317250]

unread,
May 14, 2002, 9:16:26 PM5/14/02
to
I can't speak for all DirectX components but DirectSound does not
subclass the window procedure. It simply uses the window handle to
determine (every 1/2 second, in a seperate thread) if the window that
corresponds to the handle has the focus (Actually, it is slightly more
complicated than that, but that is close enough for this discussion).
You can feel free to use the desktop window or console window for the
window handle if you are going to create GLOBAL_FOCUS buffers.

Regards,

--
Alan Ludwig
Software Design Engineer -- Windows AV Platform -- Microsoft

Michael Chase

unread,
May 17, 2002, 12:10:18 PM5/17/02
to
Ahhh... A real answer, so this is the way right?

HWND hWnd = GetForegroundWindow();
if( hWnd == NULL )hWnd = GetDesktopWindow();

Use hWnd and set the DSBCAPS_GLOBALFOCUS bit on
creation of buffers... Viola!

Thanks. That did it.

>.
>

Alan Ludwig [MS] [317250]

unread,
May 24, 2002, 12:31:49 AM5/24/02
to
"Michael Chase" <cha...@comtrix.com> wrote in news:4b0401c1fdbd$56922870
$3aef2ecf@TKMSFTNGXA09:

> Ahhh... A real answer, so this is the way right?
>
> HWND hWnd = GetForegroundWindow();
> if( hWnd == NULL )hWnd = GetDesktopWindow();


Actually, you shouldn't use the foreground window. There is no gaurentee that
your app has the focus at the exact time that the function is called. If that
isn't your window, you have no control over its lifetime. It may disappear
before you're done with your sound.

If you are going to use this technique you are better off with a window that
you can gaurentee will be around at least as long as your process. Use the
desktop window or the console window, not just some random window.

Regard,

0 new messages