We're Sorry, but the Clip You Selected Isn't Available From Your Location

Illustration

As I live in Croatia, I am used to videos being blocked.

With all this Conan vs. Leno controversy, I decided to check what exactly is going on. One of videos I tried to watch was on The Jay Leno Show page. It featured standard “We’re sorry”, but only after giving me advertisement message before.

If they decide not to offer their program in my country, I can live with this. But how can one in straight face say that while actual program may not be available for me, advertisements are fine.

And it is not only videos. It apply when you are buying stuff too. It is books on Amazon, audio books on Audible, and quite a few other places.

I hate when I need to download content from unauthorized source (e.g. torrents) just because they do not want my money. If you do not consider my money “green” enough, it is fine, but then do not complain that piracy is wide-spread when you are one that is forcing it.

GetLastWin32Error

static void Main(string[] args) {
    if (!NativeMethods.DeleteFileW(@"X:\NonExisting.txt")) {
        throw new Win32Exception(Marshal.GetLastWin32Error().ToString());
    }
}

private static class NativeMethods {
    [DllImportAttribute("Kernel32.dll", EntryPoint = "DeleteFileW", CharSet = CharSet.Unicode)]
    [return: MarshalAsAttribute(UnmanagedType.Bool)]
    public static extern bool DeleteFileW([InAttribute()] [MarshalAsAttribute(UnmanagedType.LPWStr)] string lpFileName);
}

This code looks quite straightforward. Function should delete file and in case of failure exception will be raised. In this particular case one would be expect either 2 (ERROR_FILE_NOT_FOUND) or 3 (ERROR_PATH_NOT_FOUND) as raised exception’s text.

However this example will most probably return 0. You can already guess from highlight that problem is in DllImport line. To make function behave properly, one parameter needs to be added:

[DllImportAttribute("Kernel32.dll", EntryPoint = "DeleteFileW", CharSet = CharSet.Unicode, SetLastError = true)]

When SetLastError is set to true, .NET will make all necessary plumbing in order to catch and store error code. This code will be available to you in GetLastWin32Error() function until some other P/Interop call overwrites it.

Although I knew all of that, I fell as a pray to this annoying bug. Reason lies in great tool - PInvoke Interop Assistant. It will generate all necessary P/Interop signatures and it is just too easy to rely on it’s judgement. At least until you find out that all those API signatures are generated without SetLastError parameter set.

If this little issue goes unnoticed, you have quite a big bug on your hands. Worse still, since GetLastWin32Error() will almost always return 0, bug will probably go unnoticed and it will manifest itself somewhere far away from function. Catching that one can be tricky.

Safely Remove Hardware

Illustration

I hate when new version of program removes one feature that I use, no matter how insignificant it may seem. Once you get used to something, it is always hard to let it go.

When you go to “Safely remove” your USB disk in Windows XP this will also close any Explorer window that has drive listed.

Then Windows Vista came. In Windows Vista you will get an error if any program is currently accessing drive that is being removed. This includes also simple viewing of content. I can understand reasoning - this was “proper” way to do things - no special behavior for any program.

It came to me as a surprise that Windows 7 brought “old” behavior back. It just feels much more humane when computer does obvious things for you. And it definitely shows problem with Windows Vista - lot of small annoying things.

Summae 1.01

Illustration

This is only small update for my Summae program. As you may know, this is small utility for calculating various sums. Supported algorithms include CRC-16, CRC-32, MD-5, RIPEMD-160, SHA-1, SHA-256, SHA-384 and SHA-512. You can use it as standalone program or as command-line replacement for some other utility e.g. md5sum or sha1sum.

New version is improved in some small details:

  • fixed text box width on Windows XP
  • last choice of methods is now remembered in main program
  • fixed issues when window would get outside of screen border

New version can be downloaded here.

Aurora

Illustration

There is yet another hole in Internet Explorer. Although usually Microsoft patches browser well before public availability of exploit, they were hit by zero-day exploit. I will not get too much into how serious this exploit is and which browser versions are exactly jeopardized, but I must comment on measures to solve it.

First measure that is recommended by Microsoft is disabling JavaScript. While this might sound like good advice five years ago, I think it is most idiotic recommendation today.

Probably every site worth seeing is using JavaScript for one purpose or another. Disabling JavaScript for most of sites means same level of usability as not visiting anything in the first place.

If this is main line of defense, maybe it is time for new browser…