How to stop a sound thread
-
Hi, everybody I meet a problem First DWORD WINAPI CA::ThreadFuncSound(LPVOID lpParam) { DWORD dwResult=0; Beep(800, 1000000); return 0; } ThenCreat a thread to sound which is suspended m_hThreadSound = CreateThread( NULL, // no security attributes 0, // use default stack size ThreadFuncSound, // thread function (PVOID)this, // argument to thread function CREATE_SUSPENDED|THREAD_ALL_ACCESS, // Start the thread with a suspend count of one &dwThreadId); And then Start the sound thread ResumeThread(m_hThreadSound); Sleep(100); Now I want to stop the speaker to sound. I ever used SuspendThread(m_hThreadSound) or TerminateThread(m_hThreadSound,0), but they can't work well. How can I solve this problem? Appreciate for any suggestions!
-
Hi, everybody I meet a problem First DWORD WINAPI CA::ThreadFuncSound(LPVOID lpParam) { DWORD dwResult=0; Beep(800, 1000000); return 0; } ThenCreat a thread to sound which is suspended m_hThreadSound = CreateThread( NULL, // no security attributes 0, // use default stack size ThreadFuncSound, // thread function (PVOID)this, // argument to thread function CREATE_SUSPENDED|THREAD_ALL_ACCESS, // Start the thread with a suspend count of one &dwThreadId); And then Start the sound thread ResumeThread(m_hThreadSound); Sleep(100); Now I want to stop the speaker to sound. I ever used SuspendThread(m_hThreadSound) or TerminateThread(m_hThreadSound,0), but they can't work well. How can I solve this problem? Appreciate for any suggestions!
Hi there to terminate a thread first call GetExitCodeThread() method passing the Thread Handle to it and DWORD reference. DWORD exitcode GetExitCodeThread(m_hThreadSound, &exitcode) ; Now call TerminateThread(m_hThreadSound, exitcode); actually u were commiting mistake by passing 0 as thread exit code in ur TerminateThread line. Tell me if i solved ur prob :-D Abhishek Srivastava Software Engg (VC++) India ,Noida Mobile no 9891492921 :)
-
Hi there to terminate a thread first call GetExitCodeThread() method passing the Thread Handle to it and DWORD reference. DWORD exitcode GetExitCodeThread(m_hThreadSound, &exitcode) ; Now call TerminateThread(m_hThreadSound, exitcode); actually u were commiting mistake by passing 0 as thread exit code in ur TerminateThread line. Tell me if i solved ur prob :-D Abhishek Srivastava Software Engg (VC++) India ,Noida Mobile no 9891492921 :)
Thanks But it does not work well yet. It seems that this operation can not stop the speaker's sounding. Have any other way? :confused::zzz:
-
Thanks But it does not work well yet. It seems that this operation can not stop the speaker's sounding. Have any other way? :confused::zzz:
Sir , u have passed 1000000 as a second param in Beep method , which means u have played a sound for almost 16 mins and this will block ur thread . so instead of issuing a command for 16 mins,do it in a While loop like this while (true) { Beep(800,100); } return ; Abhishek Srivastava Software Engg (VC++) India ,Noida Mobile no 9891492921 :)
-
Sir , u have passed 1000000 as a second param in Beep method , which means u have played a sound for almost 16 mins and this will block ur thread . so instead of issuing a command for 16 mins,do it in a While loop like this while (true) { Beep(800,100); } return ; Abhishek Srivastava Software Engg (VC++) India ,Noida Mobile no 9891492921 :)
:) it is not very good for the soud souds off and on, interrupted Is it better if uninterrupted ?