0

I got an automatic test suite for an old application that needs to be tested regularly. Both, test and the legacy application are separate processes. Within my test I need to detect, if a specific sound file has been played by the application. I know, the application plays the sound using the PlaySound method (https://learn.microsoft.com/en-us/previous-versions/dd743680(v=vs.85)).
Using my test process (C# code) I can create situations that should make the application play the sound. But how can I implement a check within the test process, that the necessary call to the PlaySound method also happens?

Do you have any chance to somehow hook detect if the application calls this PlaySound method?

(Or will I really need to monitor the sound output and check, that it contained this file theibry? Lets hope not, but if so, whats an appropiate way to monitor and detect such audio samples?)

Anoni2
  • 81
  • 7
  • If you want to register a callback on a WinAPI such as PlaySound to be notified when another process call it, that is not possible, as I know. Windows is not that interoperable at such a level, as I know. Having said that, does only know whether the system or perhaps some process is currently playing sound or not will be sufficient? –  Aug 08 '21 at 10:32
  • Does [this](https://stackoverflow.com/a/293658/10318835) help? Also you could try Process Monitor with command line arguments to log opening the sound file (if it resides on disk). – Steeeve Aug 08 '21 at 12:22
  • @Steeve Unfortunately this is not sufficient, as the process under test is runnning for a few minutes, and the sounds should signal e.g. an error injected by the test under certain conditions. – Anoni2 Aug 08 '21 at 12:35
  • @OlivierRogier This would also be a sufficient approach, yes. It's quite unlikely, that other systems would be able to play such a sound, so it would be fine to listen to the systens audio too and identify, that the required .wav file (we got a few different sounds) gets played. – Anoni2 Aug 08 '21 at 12:37
  • @Anoni2 by hooking your process with detour or easyhook you can monitor every api call, if I'm not wrong. It's seems to be not easy, but doable. Or am I missing something? – Steeeve Aug 08 '21 at 12:44
  • Does this answer your question? [How to check programmatically if an app is making a certain sound?](https://stackoverflow.com/questions/42494488/) and [Check what programs are playing audio?](https://stackoverflow.com/questions/14850951/) and [Determine if windows is currently playing sound](https://stackoverflow.com/questions/45422255/) and [How to know if a sound is playing using c#?](https://stackoverflow.com/questions/23829571/) and [How do I figure out if Windows is currently playing any sounds?](https://stackoverflow.com/questions/6616227/) –  Aug 08 '21 at 12:51
  • @OlivierRogier This might indeed be really helpful approaches. Eventhough I hoped to get a hook on the PlaySound call, its still a probably quite helpful way to check if a windows process plays a certain sound. I'll check the answers in detail now. – Anoni2 Aug 08 '21 at 13:16
  • @Anoni2 [Not possible](https://referencesource.microsoft.com/#System/sys/system/Media/SoundPlayer.cs,dcca8e053831d126,references), as I know : this WinAPI has no callback parameter to register with to get informed of start and stop playing a wave form, and you cannot bypass it unless you hack machine code to inject yours into the Winmm.dll which is prohibited by Microsoft and will be considered a virus by any good protection software. The interception of all WinAPI calls from any process will be the same, beyond the simple behavior of a supervisor in debugger mode. –  Aug 08 '21 at 13:30

0 Answers0