Question Sounds in the Registry

BubbaBeans

Member
Joined
Oct 5, 2009
Messages
5
Location
Redding, CA
Programming Experience
10+
I know how to access and play the system sounds using vb.net, and I also know that using the registry to save users' settings isn't ideal, however...

The details of my project are rather long and drawn out, so I'll skip most of them. Basically my program is loaded onto several computers on our network. The entire purpose of this program is to sound various alarms on different dates and times.

Apparently I am to set up the program so that the different alarm sounds can be configured through Windows' control panel. Ok, that's all fine and good. I can add the program into the appropriate part of the Registry in order to make that happen.

The problem is reading the the information back. Under the name of the app, I have four different subkeys, each with the name of one of the alarms. Under those keys are two other subkeys, .default and .current.

How in the world do I get the sound from .current to play?!?! For some weird reason I get nul returned any time I try to read the key that I created.
 
This appears to be what I need, but it is used in C/C++, and I'm writing vb.net. How annoying! (And I don't feel like rewriting the entire application in C++. (Been a LONG time since I've done any coding in ANY version of C!)
 
You don't have to write any C++. You can call Windows API functions, or any exported C/C++ functions for that matter, using the Declare keyword or the DllImport attribute. The technique is called Platform Invoke and there's a web site called PInvoke.net that provides managed declarations of most Windows API functions.
 
Further Question

PlaySound works great for me when I want to play system sounds, but for some reason doesn't seem to find and play the sounds for my program. During the install process, my program adds keys.

For instance, HKEY_CURRENT_USER\AppEvents\Schemes\Apps\DANotifier has my four subkeys, 1 Hour, 12 Hours, 24 Hours, After Hours. Each key has a .current and .default key, with the names of the appropriate wav files in place. I can change the sounds through the control panel, so I know the keys are in the right place.

However, when I use

PlaySound("1 Hour", IntPtr.Zero, SoundFlags.SND_ASYNC Or _ SoundFlags.SND_ALIAS)

I get the default Windows sound, rather than the sound I have assigned. What in the world am I missing?!?!?
 
Back
Top