VA_IAudioSessionControl2_GetProcessId hangs the script Topic is solved

Get help with using AutoHotkey and its commands and hotkeys
User avatar
uname
Posts: 22
Joined: 25 Oct 2013, 12:50

VA_IAudioSessionControl2_GetProcessId hangs the script

15 Jun 2020, 07:49

Recently I've noticed my main persistent script hangs sometimes, I've traced the issue to the VA_IAudioSessionControl2_GetProcessId call, the script below never show the Msgbox and can be closed by process termination only.

Code: Select all

IID_IAudioSessionManager2 := "{77AA99A0-1BD6-484F-8BC7-2C654C9A9B6F}"

dev := VA_GetDevice()
VA_IMMDevice_Activate(dev, IID_IAudioSessionManager2, 7, 0, mgr)
ObjRelease(dev)
VA_IAudioSessionManager2_GetSessionEnumerator(mgr, enm)
ObjRelease(mgr)
VA_IAudioSessionEnumerator_GetSession(enm, 0, ssn)
VA_IAudioSessionControl2_GetProcessId(ssn, PID)
ObjRelease(ssn)
ObjRelease(enm)

MsgBox % PID
The code has worked flawlessly for last 8 years, something changed in my system and I can't find the problem myself
AHK 1.1.32.00 x64 and WIndows 10 x64 Pro 2004
User avatar
uname
Posts: 22
Joined: 25 Oct 2013, 12:50

Re: VA_IAudioSessionControl2_GetProcessId hangs the script

21 Jun 2020, 22:02

Can somebody test the code on Windows 10 2004 please.
lexikos
Posts: 6854
Joined: 30 Sep 2013, 04:07
GitHub: Lexikos

Re: VA_IAudioSessionControl2_GetProcessId hangs the script  Topic is solved

01 Jul 2020, 04:08

I have deleted the "duplicate" topic from Bug Reports. An issue in a user-defined function occurring after a Windows update is clearly not an AutoHotkey bug.

In this case, I'm fairly certain the issue is because you are making an invalid call. IAudioSessionEnumerator::GetSession() is documented as returning IAudioSessionControl, not IAudioSessionControl2. As the latter inherits from the former, you might get an IAudioSessionControl2 anyway, but it was never guaranteed. You must query for the correct interface with ComObjQuery.

On my system (Windows 2004) your script does not stall, but returns PID 0 for every session.
User avatar
uname
Posts: 22
Joined: 25 Oct 2013, 12:50

Re: VA_IAudioSessionControl2_GetProcessId hangs the script

01 Jul 2020, 16:36

Thank you!

So all this time my script was missing the lines

Code: Select all

VA_IAudioSessionEnumerator_GetSession(enm, 0, IAudioSessionControl)
ssn := ComObjQuery(IAudioSessionControl, "{BFB7FF88-7239-4FC9-8FA2-07C950BE9C6D}")
ObjRelease(IAudioSessionControl)
By the way, the source was posted here
Last edited by uname on 02 Jul 2020, 05:13, edited 1 time in total.
malcev
Posts: 589
Joined: 12 Aug 2014, 12:37

Re: VA_IAudioSessionControl2_GetProcessId hangs the script

01 Jul 2020, 18:33

To get a reference to the IAudioSessionControl2 interface, the application must call IAudioSessionControl::QueryInterface to request the interface pointer from the stream object's IAudioSessionControl interface
https://docs.microsoft.com/en-us/windows/win32/api/audiopolicy/nn-audiopolicy-iaudiosessioncontrol2
It is not good that library va.ahk does not check errors.
lexikos
Posts: 6854
Joined: 30 Sep 2013, 04:07
GitHub: Lexikos

Re: VA_IAudioSessionControl2_GetProcessId hangs the script

Yesterday, 21:33

@malcev, as with DllCall, if you pass invalid parameters, that's your problem. One can only check the type of an interface pointer if it is a valid interface pointer derived from IUnknown, which is the case here, but not for all invalid parameters. These functions are basic low level wrappers for interface methods. A higher level library is safer and has no need for interface type checks, because you do not deal with interface pointers - for instance, VA_GetMasterVolume("", "playback").

I don't know why you linked to IAudioSessionControl2. Anyone can find the documentation by searching.

Return to “Ask For Help”

Who is online

Users browsing this forum: AHKStudent, anissem, carluig, Google [Bot] and 125 guests