Set audio endpoint devices application specific (programmatically) - c++

Link to the bug report on 'Feedback Hub'
An audio endpoint device, from here on referred to as 'endpoint', is a physical or virtual audio output or input device.
With the Windows 10 April Update 1803 the long overdue 'App volume and device preferences' have been introduced. These settings allow more control over audio stream management as it is now possible to set different endpoints for different applications, no matter whether that particular application comes with an endpoint selection or not.
However, there is an issue where the audio of a program, whose endpoint is non-default, is streamed through the default endpoint (or not at all) after it has been closed and launched again, although the endpoint is displayed correctly in the settings:
As far as I know the issue can be recreated on a Windows 10 machine (version 1803 or higher) with any virtual or physical endpoint and an affected program. I used 'VLC Media Player' in this example (disregarding the fact that it comes with an endpoint selection) as it is well known and widely accessible, which should make it easier to recreate the issue.
What I'm searching for...
... is a programmatically solution to switch between endpoints, which ideally can be launched in form of a script to set the correct endpoint with an application launch.
For my purpose it would be enough to have to adjust the device instance path manually, as the device would be always the same, but I'm not going to complain about a solution which retrieves the device instance path from the registry, too.
Defined endpoints and the device instance path of the device they are using can be retrieved from the subkeys of the key HKEY_USERS\# YOUR SID #\Software\Microsoft\Multimedia\Audio\DefaultEndpoint. I don't know how windows generates the name of the subkeys or where they can be found. If I had to take a wild guess, I'd say these are Application IDs (feel free to correct me if I'm wrong).
The device instance path itself can be found in the Device Manager (under 'Audio inputs and outputs' double click the desired device, navigate to the tab 'Details' and select 'Device instance path' from the 'Property' drop-down menu).
Additionally the entry about Audio Endpoint Devices and Stream Management in the Microsoft Docs might be helpful, but that is way above my head.
A possible but impractical workaround...
... would be, to manually set another endpoint for the application and switch back to desired endpoint at every launch of said application (as shown above).
But not just takes this at least 10 seconds at each and every launch, you might even forget to do this as the audio might just get streamed through the default endpoint *¹.
The alternative to the latter is, that no audio will be streamed at all *² or in some cases it actually works *³.
*¹ e.g.: VLC Media Player, Tom Clancy's Rainbow Six Siege (although the audio will be streamed correctly during the splash screens)
*² e.g.: Call of Duty 4: Modern Warfare, Call of Duty: Modern Warfare 2, Call of Duty: Modern Warfare 3
*³ e.g.: Window Media Player, Microsoft Edge, Firefox
Observations
VLC Media Player comes with an endpoint selection, but so does TeamSpeak 3 and, unlike VLC, it skips the Windows settings completely.
Call of Duty not streaming any audio most likely is connected to the engine as I didn't encounter any other application doing something similar.
Windows Media Player, Microsoft Edge and Firefox are the only programs (I tested so far) which work fine. They have no endpoint selection (I'd know of) and will use the correct endpoint after closing and launching it again. It should be noted, however, that Firefox and Microsoft Edge will show multiple instances in the "App volume and device preferences" when adjusting the endpoint.
Disclaimer
I already tried two 3rd party softwares: 'Audio Router', which didn't work at all and 'CheVolume', which doesn't solve the issue and constantly crashes while doing so.
This question is based on one I asked over at Super User (here), where I didn't get an answer I was able to work with due to my lack of knowledge regarding actual programming (I'm only somewhat familiar with Batch and PowerShell). I'm well aware that neither Stack Overflow nor Super User are script writing services, however, the issue is not being fixed with the Windows 10 October Update 1809 and I see this as a problem which is affecting not just me and with that would be helpful for multiple people after me. Feel free to write a comment or propose an edit if you see this differently.
I'm also not sure whether the tags 'audio-streaming' and 'endpoint' should be used in this context, please propose an edit if they shouldn't or you can think of any better.
Edit - 05/11/18
Using the 3rd party software 'EarTrumpet' I was able to overcome the issue with the 'Call of Duty' games (no audio at all after restarting), however, 'VLC Media Player' would not restart after I assigned a non-default endpoint with 'EarTrumpet' until I closed 'EarTrumpet' again and the issue with 'Tom Clancy's Rainbow Six Siege' remains the same.
Edit - 18/01/19
Added link to a bug report I created on the 'Feedback Hub' 2 month ago.
Edit - 20/01/19
After doing some testing again it should be noted that having 'EarTrumpet' run in the background will keep a non-default endpoint for 'VLC Media Player' across restarts, however, 'VLC Media Player' will only (reliably) restart when the non-default endpoint was set in the 'App volume and device preferences'.

I do not have any solution regarding a programming language to handle such events.
But I can recommend EarTrumpet app to handle this change more quickly https://www.theverge.com/2018/6/13/17457778/eartrumpet-windows-10-audio-app
(Windows store: https://www.microsoft.com/en-us/p/eartrumpet/9nblggh516xp?ranMID=24542&ranEAID=nOD%2FrLJHOac&ranSiteID=nOD_rLJHOac-hUn6PgKuMKwQLdrzRqnPTA&epi=nOD_rLJHOac-hUn6PgKuMKwQLdrzRqnPTA&irgwc=1&OCID=AID681541_aff_7593_1243925&tduid=%28ir__qwqlg6jd0jba3y9hpnbvikaite2xk6kuyv9udtr100%29%287593%29%281243925%29%28nOD_rLJHOac-hUn6PgKuMKwQLdrzRqnPTA%29%28%29&irclickid=_qwqlg6jd0jba3y9hpnbvikaite2xk6kuyv9udtr100&activetab=pivot:overviewtab )
I will update the answer if I find a easy way to script/program a change of output on each app.

Related

Windows 10 C++ NetworkExplorerPlugins context menu handler example

I have numerous ESP8266 / ESP32 / STM32 IOT devices, running my own firmware. One of the functions is a uPNP/SSDP provider which allows remote control from Amazon Echo devices and/or anything that can "speak" SSDP. I managed to find enough info to get these devices automatically added to the Windows network "Home Automation" view by tweaking the registry:
My next step is to have what I think is a "context menu handler" so I can right-click the relevant device and have on/off/toggle options that then send the relevant SOAP envelop to the device to switch on etc. I'd also like to either change the icon (or add an overlay) in-flight to show the on/off state of the device, but that is icing on the cake.
I am having having serious difficulty finding an example C++ framework I can cut and paste to start me off that is relevant, accurate and modern. Every example I find is either for an explorer file menu, or in C#, or literally decades out of date: no doubt much is similar but it is "hooking" the thing in to the Network Pane of Windows 10 that I simply can't find how to do. Even on the MS developer site the information talks mostly about Vista and even XP(!) and is generally quite incomprehensible. The clearest site I could find (dated 2018) recommended a book on Windows Shell programming that was published in...wait for it...1998!
I know I'm going to have to build a DLL - I'm fine with that, I just need a good "leg-up".
"NetworkExplorerPlugins" brings up precisely 0 hits here.
I have been searching unsuccessfully for weeks - can anybody point me to a recent Windows 10-specific C++ example or tutorial that will get me started?

How to Know when device is removed from network Using Bonjour C library

I am using DNSServiceDiscovery C Library Bonjour to detect Camera and Printer.I am Using Windows 7 and Visual 2010.
http://developer.apple.com/library/mac/#documentation/Networking/Reference/DNSServiceDiscovery_CRef/dns_sd_h/index.html
I am able to detect the Camera and Printer.
Now I am wondering how to Get notification when device is removed from the network.
Suggest me how to implement this feature.
If you keep your DNSServiceBrowse operation running, you will eventually get notified when one of the previously-found services appears to no longer be present. This isn't an instantaneous thing, however. Keep in mind that the primary use case for Browse is to populate a UI from which the user can select a service.
After researching thoroughly, I can't find a way to do this.
There is no way in Bonjour Api to know when the device is removed.
If the device exposes some service and client program is synch up with that, probably we can know about it.I am doing the same for my application.

Windows Mobile C++ - Application design-type question

i have my application skeleton working as expected - it might be that somebody has a good solution to what i am trying to achieve within Windows Mobile 6.5 enviroment.
Here's what i am actually trying to do:
Application running in background ( it sends periodically network packets to office server, packets are loaded with statistics data and pushed onto the server via Winsock2 and custom made protocol ).
What 'background' means here - is an application that creates a window of 0,0 size and is minimized - i am thinking about going into the services with this, but the next thing that i require stops me today from doing this.
I need this application to be 'visible' somewhere as an icon - i already know i can't do this in the 'tray' area as stated in this post:
Windows Mobile C++ Tray Icon
Now i was trying to utilize the: SHNotificationAdd - but this is ok for a 'notification' as the name says type of thing. So it popsup and you can click to hide it - this is bad.
What i need to achieve is an icon that is visible during the application run cycle, so it flashes when there is no synchronization possible, it changes the icon when synchronization is done.
I am a bit worried it can't be done - i even tried to go and code the "Home" plug-in for this purpose, but was told that some people have themes installed and it might be that my application won't be even visible to those guys.
Now as we're going to deploy it to few places around ( 3 data centers spread across the country - around 130 people smart phones only ) - i need to be sure this application is visible even when there is a theme applied or customization done.
Any chance this can be done ?
I was kinda sure it can be done with a classic 'tray icon approach' until i found that 'tray icons' are not supported for normal applications.
If there is something i can do - i would really appreciate if somebody could shed a bit of light on this for us all please.
You'll have to move to a Windows Mobile paradigm for your app, as what you're trying to do isn't possible (as you're finding). A home screen plug in has problems if the user customizes it, and you are correct that there is no "tray". The icons in the corner (battery, signal strength, etc) are reserved for OEM use only.
My recommendation would be to actually create a visible Form for your application. Maybe it shows just some simple status info like last upload time, amount of data transferred, etc.
You then use the notifications to place a user notification during "events" such as the inability to connect (replacing your "flashing icon" idea) or when synchronization is complete (replacing your "changed icon" idea).

How can I notify my application that the default sound playback device has changed?

I have two sound cards on my Win XP SP3 computer, and I've written a C++ app, with which I change the default playback device by editing the following Registry entry:
regKey = Registry.CurrentUser.OpenSubKey(#"Software\Microsoft\Multimedia\Sound Mapper", true);
My app changes the "Playback" key value for the purposes of using the first or second sound card as the default playback device.
The problem is when I change the default device, the application still uses the old one (which was set as the default when the program starts). If after change, I launch the application again, everything works fine and I can use the "new" default playback device.
How can I "tell" for my application that I have changed the default device? By what way does the application read and store the variable on starting up which sound device is default in Windows? Is there any solution for my problem?
The Registry is essentially a database that stores the default settings. Modifying the values in the registry does not cause any application, nor Windows itself, to re-initialize its settings with the new, updated values. Raymond Chen discusses this very thing with reference to user interface settings.
Also consider that things like this are very likely to change in later versions of Windows. If you ever decide to update to Windows Vista or 7, you'll be back here again asking more questions because your sound-switcher application won't work anymore. The later versions handle audio devices very differently than they were handled in XP; for starters, they're now based around the Core Audio APIs.
Therefore, for reasons that should be obvious, modifying registry values is not the preferred way to modify your computer's configuration.
But if you're just trying to make a particular application notice that you've changed the value in the registry, the simple solution is the RegNotifyChangeKeyValue function. This essentially subscribes the application to receive notifications each time the value of a particular registry key changes.
The correct solution for Windows Vista and later is available here.

Spooling Thermal Shipping Label Data From Web Site

I need help trying to get thermal shipping label data from a Web site to a local Zebra printer. The data itself is just plain text but spooling it from a Web site seems to be very difficult for some reason. Does anyone have any experience with this? I am using ColdFusion 8 and Windows Server 2008.
Your print data could be sent with a MIME type (there probably is one for it, but you could make one up too)
On the client's PC, they could have that MIME type mapped to a program that simply prints whatever it receives.
Setting the MIME type on a PC can be done with code or a .REG file. If you control the user's environment, that's pretty simple. Making a program that dumps whatever it receives is also easy. That would be a nice task for Visual C or good, old VB6. Very little code. As long as the user has the .EXE and the .REG file, they'll print reliably, every time, without the browser's crap getting in the way. (think of this as what happens when you click a link to a PDF - Acrobat opens. Well, have the little printing EXE open for your file type - easy).
This is familiar to me... I think I did this with a proprietary font set... AH! Yes, I had to do this to generate mortgage documents that used proprietary fonts for drawing the pretty lines. I was able to take a proprietary, stand-alone mortgage origination server, share the folder where the mortgage .PRN files had been created. A Web server with access to that share enumerate the files in the share to a Web page, then, when users clicked on a file, the .PRN would stream to their PCs where a corresponding .EXE would see it as one of its own and send it to the correct output device (a designated printer at their location). That dumb little piece of code eliminated 126 document servers (and their maintenance and licensing costs) instantly and mortgage documents were never lost or sent to the wrong branch by mistake again. I think it took 3 hours to get it all working from inception to testing at the branches.
Yeah, same thing here. It'll work. Trust me. It'll work.
I was unclear by your question as if the Zebra printer is connected to the web server and what software the server is running. If you are trying to send the data to a printer connected to the web server, I used the following information to send label data to a Zebra thermal printer in an Intranet solution and it worked great:
How to send raw data to a printer by using Visual C# .NET
Perhaps you can adapt this solution to your environment.
I fiddled about with this problem for ages. In the end I had to create downloadable printfiles. The user downloads them and then copy (MSDOS) them to the printer.
There were two main issues:
generally speaking, you can't print
from a website unless you open the
file (ie the file becomes local)
the print drivers on the user's (Windows)
machine add non-printing characters
to the barcode file as it is sent to
the printer
We installed a batch file (which runs copy instead of print) on all client machines that need to print barcodes and we added a right-click menu item to run the batch on files named *.barcode.
I'll be watching this thread to see if anyone has found a more direct solution. But this was the only thing we could do given the parameters of our situation.
I don't know if I have fully understood your problem or the exact environment but I have answered a similar question here with an example for ASP.NET (C#). That solution is mainly for a known printer (specific IP and port). If you have several clients with their own label printers the solution could be used for that as well. But then you have to make a solution where the clients are able to set their own IP and port of their label printer. They also might need to make a port forward for the traffic in their firewall. The webpage then just prints to the specified IP and port. You can also use a domain name instead of IP.
Perhaps you could try this:
http://code.google.com/p/jzebra/
This project allows the ZPL commands to be sent to the printer via a web browser.