🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: borland.public.cppbuilder.multimedia
Article #201

Re: CALLBACK_THREAD

#201
From: Remy Lebeau (TeamB)
Date: Wed, 28 May 2008 20:08
97 lines
4014 bytes
"Isaac" <nospam@nospam.com> wrote in message 
news:483cd729$1@newsgroups.borland.com...

> I thought that it may not be as simple as putting ThreadID
> in the parameters of waveOutOpen; that by doing so the
> messages were actually being sent to the main application
> instead.

In the code you have shown now, you are not sending the messages to the main 
thread at all.  So the TForm (or TApplication) cannot process the messages 
because they will never see them.

> So I wrote a function that sets the thread ID to test this
> (but no joy as well).

Your code is wrong for that.  It is calling waveOutOpen() in the thread 
constructor before the myThreadID variable has a chance of being assigned 
any value.  Since you are using the thread's ThreadID property anyway, your 
myThreadID variable is redundant.  You are also calling waveOutOpen() before 
the thread's message queue is even created.

>         BEGIN_MESSAGE_MAP
>            MESSAGE_HANDLER(WOM_DONE, TMessage, OnWaveMessage)
>         END_MESSAGE_MAP(TThread)

You can't use a message map with a TThread.  You will have to code the 
message pump manually by calling Get/PeekMessage(), TranslateMessage(), and 
DispatchMessage() directly.  For example:


    __fastcall TForm1::TForm1(TComponent* Owner)
        : TForm(Owner)
    {
        playWave = new LineOut(false);
        ...
    }


    __fastcall LineOut::LineOut(bool CreateSuspended)
        : TThread(CreateSuspended)
    {
        ...
    }

    void __fastcall LineOut::Execute()
    {
        HWAVEOUT WaveHandle
        MSG msg;

        // create message queue
        PeekMessage(&msg, NULL, 0, 0, PM_NOREMOVE);

        waveOutOpen(
            &WaveHandle,
            WAVE_MAPPER,
            &WaveFormat,
            this->ThreadID,
            (DWORD) this,
            CALLBACK_THREAD);

        while( !Terminated )
        {
            if( MsgWaitForMultipleObjects(0, NULL, FALSE, 1000, QS_ALLINPUT) 
== WAIT_OBJECT_0 )
            {
                while( PeekMessage(&msg, NULL, 0, 0, PM_REMOVE) )
                {
                    switch( msg.message )
                    {
                        case MM_WOM_DONE:
                        {
                            //...
                            break;
                        }
                        //...
                        default:
                        {
                            TranslateMessage(&msg);
                            DispatchMessage(&msg);
                            break;
                        }
                    }
                }
            }
        }

        waveOutClose(WaveHandle);
    }

> I'll lookup TApplication::OnMessage, thanks!

That will only work if you use the global MainThreadID as the ThreadID 
passed to waveOutOpen().


Gambit 
Technical Details
Message-ID: <483dbc02$1@newsgroups.borland.com>
Path: arc1-ca.pugleaf.net!g2news1.google.com!news1.google.com!news2.google.com!eweka.nl!lightspeed.eweka.nl!213.132.189.2.MISMATCH!multikabel.net!feed20.multikabel.net!newsfeed.freenet.de!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mail
References: <483c134e$1@newsgroups.borland.com> <483c719a$1@newsgroups.borland.com> <483cd729$1@newsgroups.borland.com>

Show Full Headers
Complete Article Headers
X-Google-Thread: 10d0fc,c44ef3876ed33b54
X-Google-Attributes: gid10d0fc,domainid0,public,usenet
X-Google-Language: ENGLISH,ASCII-7-bit
From: "Remy Lebeau \(TeamB\)" <no.spam@no.spam.com>
Newsgroups: borland.public.cppbuilder.multimedia
References: <483c134e$1@newsgroups.borland.com> <483c719a$1@newsgroups.borland.com> <483cd729$1@newsgroups.borland.com>
Subject: Re: CALLBACK_THREAD
Date: Wed, 28 May 2008 13:08:49 -0700
Lines: 99
Organization: Lebeau Software
X-Priority: 3
X-MSMail-Priority: Normal
X-Newsreader: Microsoft Outlook Express 6.00.2900.3138
X-RFC2646: Format=Flowed; Original
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.3198
NNTP-Posting-Host: 207.178.157.90
Message-ID: <483dbc02$1@newsgroups.borland.com>
X-Trace: newsgroups.borland.com 1212005378 207.178.157.90 (28 May 2008 13:09:38 -0700)
Path: arc1-ca.pugleaf.net!g2news1.google.com!news1.google.com!news2.google.com!eweka.nl!lightspeed.eweka.nl!213.132.189.2.MISMATCH!multikabel.net!feed20.multikabel.net!newsfeed.freenet.de!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mail