Design considerations for Windows Media Center applications on 64-bit operating systems
A little while ago, I wrote this blog post describing some changes that were made to the Q podcast and video blog client sample application that is included in the Windows Media Center SDK for Windows Vista. Those changes were made to better support running the Q application on Windows Media Center extender devices.
While we were working on this change, we ran into an interesting issue that affects 64-bit systems that I want to describe in more detail. The specific issue involves how applications are hosted within Windows Media Center. On 64-bit systems, applications are hosted by the 64-bit version of the ehExtHost.exe hosting process. As a result, applications that attempt to access the registry using default registry API calls will be returned values from the 64-bit registry view (as opposed to the reflected 32-bit registry view).
This caused some problems for the redesigned Q application because the new code attempts to read from a registry value under HKEY_LOCAL_MACHINE\Software\Microsoft\Q, which is a location affected by registry reflection on 64-bit operating systems. However, the Q application's assembly is a processor-neutral (MSIL) assembly, and as a result, we wanted to create a single installer that would work for both 32-bit and 64-bit systems.
Our initial solution was to create a 32-bit installer that installs the MSIL assembly to the GAC and writes the HKEY_LOCAL_MACHINE registry value, and to have the code use standard registry APIs to read data from this registry location. With that version of the code and the installer, the registry value was written to the 32-bit registry (because it is a 32-bit MSI), but the Q application never found the registry value (because standard registry APIs attempt to read from the 64-bit registry), and no RSS feeds got registered by default.
We next attempted to set the msidbComponentAttributes64bit value in the Component table for the component that installs this registry value. This strategy created the registry value in the 64-bit registry and Q worked as expected. However, this behavior cannot be relied upon - Windows Installer does not officially allow authoring 64-bit components in a 32-bit MSI. Doing so will generate ICE80 validation errors, and part of the Windows Vista logo program requires that MSI packages not have ICE validation errors like this.
That left us with the following options:
- Create separate MSI-based installers for 32-bit and 64-bit operating systems
- Modify the code to use P/Invokes to turn on/off mirroring at runtime to try to find the registry value - specifically, we can use the RegOpenKeyEx API with the KEY_WOW64_32KEY flag; P/Invokes are necessary here because this flag is not supported in .NET Framework registry classes
- Move the registry value to a part of the registry that is not mirrored (such as HKLM\System\*)
- Modify the code to check in HKEY_LOCAL_MACHINE\Software\Microsoft\Q and if that is not found, fall back and look in HKEY_LOCAL_MACHINE\Software\Wow6432Node\Microsoft\Q
The first option is probably the cleanest, but was too involved for an SDK sample application so we decided not to do that at this time. I will post a WiX-based sample in the near future for anyone who would prefer to use this option for their application.
The second option involved writing a lot of additional code, which we did not have time for before the SDK was scheduled to ship.
There is not a logical location in the registry to use for the third option, especially considering that we could not use HKEY_CURRENT_USER or else we would re-introduce the Windows Media Center extender problem we were trying to solve.
Ultimately, we chose the fourth option, and the sample code that shipped in the final release of the Windows Media Center SDK for Windows Vista includes logic to look in the 64-bit registry and if the value that points to the OPML file is not found, it then looks in the 32-bit registry. If the registry value is not found in either location, then Q skips populating RSS feeds altogether.
The important overall point of this blog post is that if you are writing a Windows Media Center application that needs to access the registry, you will need to take special care in how you design your application and your installer in order to ensure that it works equally well on 32-bit and 64-bit versions of Windows Media Center on Windows Vista Home Premium and Ultimate editions.