Article View: borland.public.cppbuilder.nativeapi
Article #3598Re: Threads, PlaySound and waveOutGetNumDevs
From: Mike Collins
Date: Fri, 19 May 2006 18:10
Date: Fri, 19 May 2006 18:10
97 lines
4491 bytes
4491 bytes
Thanks for the reply remy - I don't really know the inner workings of the
try...catch / __finally systems. The GetTokenData simply communicates with a
third party hardware token, namely rainbox iKeys. It does very little but
i've included the code below just for reference. Obviously it's a bit more
complicated once i've detected the hardware and read in it's data but the
code below is a stripped down version that i'm testing and it still
generates the same problems...
One things are appearent, the waveOutGetNumDevs() does not seem to be
working as expected - on some of the testbeds that I have tried it does not
report the existance of any soundcards when they are clearly there and
present - i have tested this ourside the scope of this thread.
The iKey comms is pretty basic, open a handle, if the handle is valid, open
a device based on that handle, read the data, close the device, close the
handle...
void __fastcall TKeyPollThread::GeTokenData()
{
IKEY_STATUS iStatus;
IKEY_HANDLE iContextHandle;
iStatus = ikey_CreateContext(&iContextHandle, 0, IKEY_API_VERSION);
if (iStatus == RB_SUCCESS)
{
iStatus = ikey_OpenDevice(iContextHandle, IKEY_OPEN_FIRST, NULL);
if (iStatus == RB_SUCCESS)
{
if (!strKeyData.bKeyPresent) <- local variable that indicates if
the token was previously present...
{
// **** Problem code...
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);
}
// ***********
strKeyData.bKeyPresent = true;
}
ikey_CloseDevice(iContextHandle);
}
else
{
if (strKeyData.bKeyPresent)
{
// The same would be true here but i haven't included the
PlaySOund becuase of the problems...
Beep(875, 150);
Beep(650, 150);
strKeyData.bKeyPresent = false;
}
}
ikey_DeleteContext(iContextHandle);
}
}
"Remy Lebeau (TeamB)" <no.spam@no.spam.com> wrote in message
news:446dfc10$1@newsgroups.borland.com...
>
> "Mike Collins" <its@TheBottomOfThePost.com> wrote in message
> news:446dbb8d$1@newsgroups.borland.com...
>
>> 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!
>
> Using a try..catch forces a stack frame to be created for the calling
> function. Without knowing what your thread is actually doing, my first
> instinct is that you are probably corrupting the stack, and the try..catch
> is hiding that since the stack is likely being restored to a proper state
> by
> the stack frame when the function exits. But that is just a guaess. You
> need to provide more details about your code in order to diangose it
> better.
>
>
> Gambit
>
>
Technical Details
Message-ID:
<446e0a32$1@newsgroups.borland.com>Path:
arc1-ca.pugleaf.net!g2news2.google.com!news4.google.com!news.glorb.com!newsfeeds.ihug.co.nz!ihug.co.nz!newsgroups.borland.com!not-for-mailReferences:
<446dbb8d$1@newsgroups.borland.com> <446dfc10$1@newsgroups.borland.com>Show Full Headers
Complete Article Headers
X-Google-Thread: 10cc67,9ea40ee0ccd38b3b X-Google-Attributes: gid10cc67,public X-Google-Language: ENGLISH,ASCII-7-bit From: "Mike Collins" <its@TheBottomOfThePost.com> Newsgroups: borland.public.cppbuilder.nativeapi References: <446dbb8d$1@newsgroups.borland.com> <446dfc10$1@newsgroups.borland.com> Subject: Re: Threads, PlaySound and waveOutGetNumDevs Date: Fri, 19 May 2006 19:10:55 +0100 Lines: 99 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: <446e0a32$1@newsgroups.borland.com> X-Trace: newsgroups.borland.com 1148062258 81.2.92.14 (19 May 2006 11:10:58 -0700) Path: arc1-ca.pugleaf.net!g2news2.google.com!news4.google.com!news.glorb.com!newsfeeds.ihug.co.nz!ihug.co.nz!newsgroups.borland.com!not-for-mail