Windows API PlaySound error / silence

Today stumbled at strange behavior of Windows API function PlaySound in combination with SND_FILENAME flag.

There are two scenarios:

  1. No sound is played, and PlaySound returns success (TRUE) in combination with SND_ASYNC;
  2. No sound is played, and PlaySound returns failure (FALSE) when using the same wav file, but without asynchronous flag.

The cause is, that system where this is happening is Windows Server 2008 R2, which is apparently missing some WAV codec. Files coded with different codec works.

Error while receiving Verisign Authenticode certificate

Today when I was downloading/receiving Verisign Authenticode certificate I got the following error window:
---------------------------
VBScript
---------------------------
Error: 1AD occured, your certificate may not be co`rrectly installed
---------------------------
OK
---------------------------

Then I was redirected to the page with the following text:
Your Certificate Could Not Be Installed Your certificate could not be installed in your web browser. The most likely reasons for this problem are:

The certificate is already installed.
Check your installed certificates. In Internet Explorer, go Tools > Internet Options and select the Contents tab. In the Certificates section, click the Certificates button. In the Personal tab, review the list of certifiicates. If your certificate is in the list, you do not need to install it again.

The browser and/or computer you are using now is not the same one used when you enrolled for your certificate.
You must use the same browser on the same computer to enroll for and install your certificate.

You are not running the latest version of Internet Explorer.
Click here to get the latest version of Internet Explorer.

The certificate database in the Web browser is not accepting the new certificate (the database may be corrupted).
Reinstall Internet Explorer and enroll again for the certificate.

It seems, that Verisign site is trying to install this certificate two times, because when I looked at the installed certificates in Internet Explorer, the certificate was already there.

Call to OpenFileDialog or SaveFileDialog hangs or freezes

Today I was debugging a very strange issue when call to OpenFileDialog and SaveFileDialog hanged, froze, never returned…

At first I thought the problem is, that call is made from SysTray (Notification area) hidden window. However, digging deeper things got more bizarre. I found a thread in MS forum, where was a workaround – add help button to OpenFileDialog.

When I say that it “hangs” I mean that the dialog does not display but no exception is thrown and the system eventually throws in a little wait cursor to indicate that the program is getting time. It doesn’t hang the entire computer, fortunately, but the application has to be terminated.

For OpenFileDialog the ShowHelp property must be explicitly set.
For SaveFileDialog the ShowHelp, CreatePrompt, and OverwritePrompt properties must be explicitly set.

It’s not consistent though. I’ve had SaveFileDialog work with just ShowHelp set in simple situations. But I have an app which didn’t start running again until I also set CreatePrompt and OverwritePrompt properties then it started working again. They don’t have to be set to true, they just have to be initialized to either true or false.

Original forum post: click here.

So I tried:
myDialog.ShowHelp = true;

And it worked. So bizarre I thought.

After little more testing I found next problem. If file is not found, then dialog must show warning that ‘File not found. Check the file name and try again.’ And it showed the warning… and hanged…

From the beginning I was ignoring one fact, that this actually is a .NET COM object, and that I am calling it from MTA threading model (multi-thread apartment). By default .NET COM objects advertise themselves as BOTH (STA, MTA), so I changed calling thread to STA. Changed CoInitializeEx to CoInitialize, and suddenly everything worked like a charm.

I am not a COM expert, so if you find some flaws please let me know in comments!