Win32 on Win64 Registry support

We've recently spent a bit of time ensuring that we have a good Win64 story for our components.  For the vast majority of our stuff, it's pretty trivial - our component's a part of the windows base, so it's a 64bit native application, done.

But of course we need to be able to support 32bit applications that use our stuff (it's audio, after all).  So I spent some time working on our 32bit-on-64bit story.  For us, the 32bit-on-64bit story was pretty easy - all our inter-process interfaces are cleanly defined using technologies like RPC, so we should be able to support 32bit applications by just putting the 32bit version of the DLL on the system (in the SysWow64 directory).

There's one situation where we need to duplicate handles from a 64bit process to a 32bit process, but the good news is that NT handles that perfectly - DuplicateHandle knows the type of the target process and does the right thing.

We finally got around to testing this last week and not surprisingly, we ran into an issue.

When running one of our 32bit components, we discovered that we couldn't access any of the data put into the registry by our 64bit applications.

So it was time to start digging.  The problem is that there are actually two separate registries on Win64, one for 32bit applications, the other for 64bit applications, so I needed to be able to open key in the 64bit registry not in the 32bit registry.

Fortunately, Raymond and Junfeng came to my rescue and pointed me to the KEY_WOW64_64KEY

In fact, Junfeng has this great post that describes exactly this issue, including how to use this key.  He also includes this link that describes the registry virtualization.

So we were set.  Except we discovered that we couldn't delete any of the keys - the RegDeleteKey API kept on failing with ERROR_FILE_NOT_FOUND.  So did ShDeleteKey.  Clearly these APIs were ALSO going to the 32bit registry.  Once again, Junfeng came to the rescue with this post (made exactly after the last one :)) that pointed to the RegDeleteKeyEx API which allows you to specify the KEY_WOW64_64KEY flag.

So problem solved, and now our stuff is working perfectly on Win64, for both 64bit and 32bit apps.  O Frabjous Day, Calooh Callay!