Wednesday, August 19, 2009

32-bit applications running under 64-bit Windows do not see the world as it really is

64-bit desktop computing is becoming more common. Major computer vendors like Dell and HP have started to give users the choice of 64-bit OS (read: Windows) in many of their models. Some of you may have already owned a 12gb+ XPS from Dell.

The specific Windows I am talking about here is Windows 7 64-bit, but the behaviors should apply to Vista 64-bit and/or XP 64-bit, as well as those 64-bit variants of Windows Servers.

In those days of Windows 32-bit, we have those Windows API libraries such as user32.dll and gdi32.dll residing in %windir%\System32. It makes perfect sense that one would expect that 64-bit API libraries in 64-bit Windows would live in %windir%\System64.

But in reality, 64-bit API libraries still live in %windir%\System32. One may say: Ok, it's alright to have both 32-bit and 64-bit libraries in the same directories, as the names of 64-bit libraries should be user64.dll, gdi64.dll etc.

But again, in reality, 64-bit API libraries still use the same name -> user32.dll, gdi32.dll etc.

So if 32-bit and 64-bit libraries share the same name, how do they both sit together in the same directory?

The truth:

  1. 64-bit Windows API libraries live in %windir%\System32
  2. 32-bit Windows API libraries live in %windir%\SysWOW64
  3. 64-bit applications directly use 64-bit Windows API libraries in %windir%\System32
  4. 32-bit applications indirectly use 32-bit Windows API libraries in %windir%\SysWOW64

The interesting part is point #4. Well, 32-bit applications cannot see the real %windir%\system32. Whenever a 32-bit application try to access %windir%\system32, the OS will translate the request to %windir%\SysWOW64, which is the place where 32-bit libraries live now.

Need a proof? Let's do an experiement. We need Internet Explorer for this test. I hope you did not remove Internet Explorer 8 yet since Windows 7 indeed allow you to. If you have really removed it, just use any 32-bit applications that can open a file to test.

1. Make sure your Windows is 64-bit. You cannot see this effect in 32-bit Windows.

2. Open Windows Explorer (which is 64-bit), go to your %windir%\system32, create a folder named "Can you see me" inside it.

3. 64-bit Windows come with both 32 and 64-bits of Internet Explorer. I need you to run the 32-bit Internet Explorer now.

4. In Internet Explorer, press Ctrl+O to show the Open dialog. Then click Browse.

5. Now go to your %windir%\system32. Can you see the folder we created in step 2? You can't. Why? Because this 32-bit Internet Explorer is actually viewing %windir%\SysWOW64 instead of the real %windir%\System32.

6. Now run your 64-bit Internet Explorer. Press Ctrl+O. Click Browse. Go to %windir%\system32. Tada! We can see the folder now!

Why in the world did Microsoft do this kind of confusing stuff? For backward compatibility reasons. Many software hardcoded itself to access %windir%\system32. If Microsoft simply created a system64, many software will need to be changed and recompiled (including those from Microsoft). And why are the names still user32.dll, gdi32.dll etc? Same reason, if the DLL name are changed, many source code will need to be changed before recompiling to 64-bit targets. By using the same directory and same naming, you do not need to change much in your software to retarget to 64-bit Windows.

Finally, how do you know whether a running application is 32 or 64-bit? You can use Task Manager to find out. A 32-bit process has a "*32" behind it's name. Those without it are 64-bits.

Wednesday, August 12, 2009

Difference between Windows 7 RTM ISO from MSDN. Create a one-for-all Windows 7 RTM ISO (Install most editions with one DVD)

MSDN provides subscribers various versions of Windows 7 RTM. According to Microsoft, all features are actually installed, no matter which edition you have in hand. For example if you have Windows 7 Home Basic, you can upgrade to Ultimate without getting another DVD. The extra features will be unlocked from your computer.

Does that mean that all these ISOs are actually the same?

For Vista, MSDN provided one DVD that included Vista Home Basic, Home Premium, Business and Ultimate. With this DVD, the Vista edition that will be installed depends on the product key you entered in Setup.

But it is different this time. Installing from a Windows 7 Ultimate ISO, setup did not accept when I tried to put product keys from other editions.

Out of curiosity, I did a binary compare on two Windows 7 ISO - Home Premium and Ultimate. The two ISO have the same size - 2,501,894,144 bytes. And the difference was only 75 bytes.

I extracted the two ISO with WinRAR, both have 874 files and 200 folders. The total size was a little bit different. So I did comparison on all files with WinMerge. Turned out that the difference was only in one file - sources\ei.cfg. The contents of this file in Home Premium:


And in Ultimate:


So if you change only that file in the ISO, you do not need to download all editions. But the best solution is just delete ei.cfg, Setup will ask you which edition you want to install if it sees no such file.

With tools like PowerISO, one can delete files in a ISO. The following shows the steps to create a One-For-All-Windows-7 DVD that you can use to install Windows 7 Starter, Home Basic, Home Premium, Professional and Ultimate. I don't know about other tools, but I used PowerISO for this.

Step 0: Download one of the Windows 7 Edition (Starter, Home Basic, Home Premium, Professional or Ultimate). Note that Windows 7 Enterprise is not included in any of these ISOs.

Step 1: Open the ISO with PowerISO (or any ISO tool of your choice) and delete sources\ei.cfg

Step 2: Save the new ISO

Step 3: Burn the ISO or mount it.

Step 4: Try to install, you will see the following screen prompting "Select the operating system you want to install"

Will Microsoft eventually release a one-for-all Windows 7 ISO as in Vista? I certainly hope so, it will save many DVDs, covers and storage space.

On Testing Windows 7 in VMware Workstation

If you are installing Windows 7 using VMware Workstation, you don't need to modify the ISO, Setup will prompt you for the edition. I tested on VMware Workstation version 6.5.2 and although it treats Windows 7 as Windows Vista, the installation went fine. I suspect that Windows 7 Setup changes its behavior whenever it finds itself living inside a Matrix world. Or maybe VMware Workstation has a way to "ask" Windows 7 Setup to let you choose the Edition ?

Tuesday, August 11, 2009

Upgrading from Windows Vista Ultimate 64-bit to Windows 7 Ultimate 64-bit

Downloaded Windows 7 Ultimate 32-bit and 64-bit RTM from MSDN. Installed the 32-bit on a Core 2 Duo 2.66Ghz in a new partition. Took only less than half an hour. The boot and shutdown speed were apparently faster than Vista.

But it spent at least 3 hours when I upgraded from Vista Ultimate x64 to Windows 7 Ultimate x64. The machine is a Core 2 Quad 2.66hz with 8gb RAM. Obviously it was no joke when Windows 7 setup said the upgrade may take several hours. At the time of the writing of this sentence, it was still being upgraded, forcing me to use another machine to blog.

The final step of the upgrade - Tranferring files, settings, and programs - was the most time-consuming, took over 2 hours in my machine. And it showed that there were 1,003,453 items to be transferred. I wonder what constituted these 1 million items. One registry key = one item? Maybe I really have that many files.

I ran the Windows 7 Setup from within Windows Vista. It warned me that SQL Server 2008 may not run properly if I upgrade without uninstalling it first. After some googling I decided to follow the advice and uninstalled it.

Seems like most settings from Vista are left untouched after the upgrade. Unfortunately there is one big problem - all my pinned programs in Start menu were gone. I have to repin those programs. Anyone experienced this?