Announcement

Collapse
No announcement yet.

Inconsistencies in WM_QUERYENDSESSION + SndPLaySound().

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Inconsistencies in WM_QUERYENDSESSION + SndPLaySound().

    I am processing the %WM_QUERYENDSESSION message like this:

    Code:
          Case %WM_QUERYENDSESSION
             If ItsOkToClose Then Exit Select
             If BlockonShutdown Then
              Function = 0        ' prevent Windows from restarting or shutting off.
              Call PostMessage(hWndForm, 16241, 0, 0)         
              EXIT FUNCTION
             End If
    
            Case 16241                        
                Call BloquearUnidad(Wparam)  ' Launch a window saying it is forbidden.
    The logic of the code is simple, if restarting or turning the computer off
    is not allowed, cancel the shut down and display a window explaining the reason.

    This is for an internet cafe, so, turning the computer off is not necessary
    or allowed to customers.

    Anyway... the thing is that the computer shutdown is successfully cancelled
    only when i remark this code:

    Code:
    	If IsTrue(Len(Trim$(Config.Sonido.Bloquear, Any Chr$(0,32)))) Then
    		If InStr(Trim$(Config.Sonido.Bloquear, Any Chr$(0,32)), Any "\/:") Then
    		 	Call SndPlaySound(ByCopy Trim$(Config.Sonido.Bloquear, Any Chr$(0,32)), %SND_FILENAME Or %SND_ASYNC)
    		Else
    		 	Call SndPlaySound(ByCopy FixName(Trim$(Config.Sonido.Bloquear, Any Chr$(0,32))), %SND_RESOURCE Or %SND_ASYNC)
    		End If 
    	End If
    This code is located in the WM_CREATE message of the window that displays the reasons to cancel shutdown.

    If i remoive or remark that code, it works smoothly. If i enable it, the computer restarts.

    Why could this be happening???

  • #2
    Check the return of SndPlaySound (true = success).

    I'm not sure that will tell you anything, but it can't hurt.

    Or maybe playing the sound ASYNCH is doing something funky. What you could try is playing the sound SYNCHRONOUSLY, but doing so in a separate thread of execution... or even launching a second process to play the sound.

    If that SndPlaySound is creating a child process, it may not be responding to WM_QUERYENDSESSION.

    Wait a minute... %SND_RESOURCE option is not valid with SndPLaySound... it is only valid with the function PlaySound which supercedes SndPlaySound, according to my SDK. That mighj explain some funkiness.
    Michael Mattias
    Tal Systems Inc. (retired)
    Racine WI USA
    [email protected]
    http://www.talsystems.com

    Comment


    • #3
      Playing the sound synchronized did the trick. Thanx Michael.

      Comment

      Working...
      X