Article View: borland.public.cppbuilder.nativeapi
Article #3593Threads, PlaySound and waveOutGetNumDevs
From: Mike Collins
Date: Fri, 19 May 2006 12:35
Date: Fri, 19 May 2006 12:35
57 lines
3504 bytes
3504 bytes
Hi all, i'm experiencing another very strange problem - hopefully someone
will be able to point me in the right direction. Basically I have a project
that has several thread, one of which is used to poll and detect the
presents of a USB token. So it basically sits in a constant loop:
void __fastcall TKeyPollThread::Execute()
{
SetName();
while (!Terminated)
{
GetTokenData();
Sleep(500);
}
}
when the token is detected (within GetTokenData) I need to either play an
audio file (33k embedded resource snippet) or play a double beep on the
computers speaker. If there is a sound card pressent, i'll play the audio
file if not, i'll do a double beep. I determine this by calling
wavOutGetNumDevs like this...
// GetTokenData....
try //*
{ //*
if (waveOutGetNumDevs() == 0)
{
Beep(650, 150);
Beep(875, 150);
}
else
PlaySound("HW_INSERT_WAV_VIS", HInstance,
SND_ASYNC|SND_RESOURCE);
} //*
catch (...) //*
{ //*
Beep(250, 5000); // *
} //*
Now, what is really, really strange is this: I had to include the try...
catch (indicated by //*) because the code was KILLING my thread. In each
execution of GetTokenData() i have a routine Beep so i can hear it polling.
Now if i run this code / app on a machine that does NOT have a sound card I
would hear the double beep then the thread would die, dead! It didn't die
on the waveOutGetNumDevs() because I could hear the double beeps but I
didn't hear the Beep from within the catch, it just died. Now, if I place
the try..catch as I have shown above(//*), if works fine, I hear the double
beep, no secondary beep from the catch and the thread does not die.
Does this make sense? Does anyone have any ideas? I know everyone will
say, what is the catch statement returning (in terms of errors) but the
simple answer is nothing - because I'm not getting that caught beep. It
just seems that by including the try catch i have somehow prevented the
crashing of the thread whist still catching nothing. What I'm basically
saying is without the try.. catch the code kills the thread, with it in, it
doesn't, BUT it doesn't catch anything either!
Thanks in advance,
Technical Details
Message-ID:
<446dbb8d$1@newsgroups.borland.com>Path:
arc1-ca.pugleaf.net!g2news2.google.com!news4.google.com!news.glorb.com!npeer.de.kpn-eurorings.net!nfeed.de.kpn-eurorings.net!npeer-devel!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mailShow Full Headers
Complete Article Headers
X-Google-Thread: 10cc67,9ea40ee0ccd38b3b,start X-Google-Attributes: gid10cc67,public X-Google-Language: ENGLISH,ASCII-7-bit From: "Mike Collins" <its@TheBottomOfThePost.com> Newsgroups: borland.public.cppbuilder.nativeapi Subject: Threads, PlaySound and waveOutGetNumDevs Date: Fri, 19 May 2006 13:35:22 +0100 Lines: 59 Organization: SDA Ltd X-Priority: 3 X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 6.00.3790.2663 X-RFC2646: Format=Flowed; Original X-MimeOLE: Produced By Microsoft MimeOLE V6.00.3790.2663 NNTP-Posting-Host: 81.2.92.14 Message-ID: <446dbb8d$1@newsgroups.borland.com> X-Trace: newsgroups.borland.com 1148042125 81.2.92.14 (19 May 2006 05:35:25 -0700) Path: arc1-ca.pugleaf.net!g2news2.google.com!news4.google.com!news.glorb.com!npeer.de.kpn-eurorings.net!nfeed.de.kpn-eurorings.net!npeer-devel!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mail