Installing Python Imaging on Windows 64-bit (AMD64) Python

If you want need a 64-bit version of this module for Google App Engine, or another project, you can run into a couple of issues. Sticking to 32-bit versions of Python and PIL avoids these issues so that may be the best direction for newbies.

The downloads on the PIL site are for 32-bit versions of Python which means that you hit runtime issues as soon as the Python script files attempt to load the 32-bit libraries into 64-bit Python. Annoyingly the installer is unaware of the ar­chi­tec­ture for the Python in­stal­la­tion it finds and will leave you with a broken PIL install. Just uninstall it from Control Panel. My first thought was to try an build from the sources but I figured someone has run into this problem.

After some searching I found a site which offers pre-built versions of many Python modules for 64-bit ar­chi­tec­tures including PIL. If you are in any way concerned about per­for­mance, or security a better solution might be to build from source or use versions from a company offering supported versions.

I downloaded the version for Python 2.5 and then discovered that it would not install. What is in­ter­est­ing is that the 32-bit installer was able to find my 64-bit Python, but the 64-bit installer was unable to find it.

After some more searching it turns out that the installer takes it’s cue from a key in the registry and the Registry vir­tu­al­iza­tion in Windows x64 was confusing it. To resolve the issue I had to export the “HKLM\­SOFT­WARE\­Wow6432N­ode\Python\Python­Core\2.5” key, remove the “Wow6432N­ode\” string using a text editor, and re-import the key so that it was at “HKLM\­SOFT­WARE\Python\Python­Core\2.5”.

After doing this the 64-bit installer for PIL detected my Python in­stal­la­tion and I was up and running.

Tagged with imaging, pil, python and windows.

Using the WTL CListBox class

Working with Win32 listbox controls is fairly simple but the code can be quite convoluted and get tedious after a while. I decided to use the WTL library to simplify some listbox handling code but it wasn't initially obvious how to do this. Hopefully this blog post will help someone else understand the basics.

Manual message processing

The majority of Win32 pro­gram­ming involves working with messages of various types that are basically #defines in header files. The Listbox control responds to messages like these:
  • LB_GETCURSEL (get the selected item)
  • LB_DELETESTRING (delete a string)
  • LB_IN­SERT­STRING (add a string)

..but you also have to make sure you use the correct WPARAM and LPARAMs.

The resulting code for adding an item to a Listbox looks like this:

TCHAR szBuffer[80] = {0};
UINT chars = GetDlgItemText(IDC_EDIT1, szBuffer, 80);
SendDlgItemMessage(IDC_LIST1, LB_INSERTSTRING, (WPARAM) 0, (LPARAM)szBuffer);

As you can see this requires a lot of work that I’ve grown tired of with years of C# coding.

Sim­pli­fy­ing with WTL

It is best to thinking of sim­pli­fi­ca­tion here with a view to the long term. You are writing C++ so this is not as straight­for­ward as WinForms or WPF.

First of all you need to create a member variable in your window class. I'm assuming you have installed the WTL AppWizard into Visual Studio and have created a Dialog ap­pli­ca­tion, but the steps are similar for other types of window. The code looks something like this:

class CMainDlg : public CDialogImpl<CMainDlg>, public CUpdateUI<CMainDlg>, public CMessageFilter, public CIdleHandler
    CListBox m_ListBox;
    enum { IDD = IDD_MAINDLG };

As you can see we have private called m_ListBox that we can reference elsewhere. Next an instance of CListBox needs to be attached to a Listbox that has been added to your dialog resource file. You do this in the OnInit­Di­a­log() method:

LRESULT OnInitDialog(UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM /*lParam*/, BOOL& /*bHandled*/)

The IDC_LIST1 parameter is the name defined in my resource file and messages are now being routed between the instance variable and the actual control.

Now in the event handling code it is possible to call the AddString() method without having to worry about message types:

LRESULT OnAddItem(WORD /*wNotifyCode*/, WORD wID, HWND /*hWndCtl*/, BOOL& /*bHandled*/)
    TCHAR szBuffer[80] = {0};
    UINT chars = GetDlgItemText(IDC_EDIT1, szBuffer, 80);
    return 0;

This is a rather naïve example as I’m not taking advantage of WTL for the Edit control, but that’ll be the subject of a future blog post.

Tagged with c, win32, windows and wtl.

Multiple Monitor/Screen Information Example

Microsoft made it very simple to get in­for­ma­tion about the displays available to Windows with the Screen class in Windows Forms. Using this class you can identify the primary screen, and get properties like size from any display device.

Screenshot of monitor/display information sample. Try it with multiple=

For anyone developing an ap­pli­ca­tion which supports multiple monitors the Screen.Bounds property may be useful in finding screen offsets. If you have multiple monitors attached try the Get Current Screen Info button on your secondary display.

Download the C# sample code and binaries to explore further. Like all good API examples I have omitted error handling ;)

Tagged with multiple-monitors, windows and winforms.

PowerShell and svnadmin dump/load

Recently I was migrating several Subversion repos­i­to­ries from a Windows server over to a Solaris one and ran into a rather frus­trat­ing issue. Actually it's quite an in­ter­est­ing problem, but was frus­trat­ing due to the size of the repos­i­to­ries involved, and my fear that repos­i­to­ries were borked.

It all started with my decision to fire up PowerShell rather than cmd.exe to do the initial dump of the re­pos­to­ries. The following code was executed to dump a repository:

svnadmin dump repositorypath > repository.dump

All seems to go to plan but this is where a silent corruption of the dump file occurs. Not suspecting that the dump file was malformed, I copied repository.dump over to the Solaris box. I issued the standard commands to create a new repository and load the dump file:

svnadmin create repository/path
svnadmin load repository/path < repository.dump

After executing the second command I got an error from svnadmin com­plain­ing about a malformed header on the dump file:

svnadmin: Malformed dumpfile header

My first instinct was to re-copy the dump file and try again, but I thought I should dump and load the repository on my Windows server. Lo and behold this fell over with the same error. At this point I was thinking something was really wrong with my SVN install and repos­i­to­ries, but then I stumbled on this newsgroup discussion.

It turns out that my problems were the result of how Windows PowerShell handles binary data that is piped on the command line. I really want to look into the details of this, but it would appear that the new found ability to pass .NET objects on the command line can mess with old school ex­pec­ta­tions of how the command line works.

Tagged with powershell, problem, solaris, subversion, svn and windows.

First impressions of Windows 7 Beta 1

After a very quick install on a Dell XPS M1710 laptop, and a few hours of messing around, I have come to the conclusion that this is going to be the best release of Windows yet. At the same time, it's not very exciting for the alpha geek in me. Perhaps it is good to have regular stable releases and leave the fireworks to user ap­pli­ca­tions?

Before I list some of the things that I like, or didn't as the case may be, I have a tip for anyone trying to get Aero running on the M1710. For some reason, Beta 1 doesn't have drivers in the box for the NVIDIA GeForce 9700M GT. Just download the mobile drivers from the NVIDIA website and install the Vista version using the "Have a disk..." option. Ignore any warnings about com­pat­i­bil­i­ty, the Vista drivers are close enough and I would expect NVIDIA to release some beta drivers for Windows 7.

What I liked

Per­for­mance im­prove­ments

This has been a problem for a large number of Vista users and Microsoft have made big strides according to my un­sci­en­tif­ic testing. Little things like searching for programs on the Start menu is noticeably quicker than Vista on the same machine. No doubt anti-virus vendors are working on ways to reduce the per­for­mance.

System protection

You can now reserve a percentage of disk space to storage of old versions of user and system files (just like Recycle Bin has done since Windows 95). This is something I would want to increase for someone like my Mum.

Task bar ap­pli­ca­tion in­te­gra­tion

The thumbnails introduced in Vista are now more useful since you view individual tabs in an ap­pli­ca­tion like Internet Explorer 8. When you have a long running task like a file copy, the progress is shown directly on the task bar when minimised.

Easier wireless network access

Clicking the network icon in the task no­ti­fi­ca­tion area now shows a list of network con­nec­tions. This makes it much easier to connect, and is similar to the experience in Apple OS X.

No­ti­fi­ca­tion area grouping

I find the pollution of the task no­ti­fi­ca­tion area to be a real pain. Every ap­pli­ca­tion thinks it belongs there and needs to be visible. With Vista you could force some items to be hidden, in Windows 7 they are grouped under a single icon. It only takes simple stuff to improve the overall experience.

Requires more thought

Taskbar ap­pli­ca­tion iden­ti­fi­ca­tion

So is Internet Explorer running, or do you have a shortcut pinned to the task bar? It's hard to see on the task bar, but I can see the rationale for this design decision. It would be nice if there was an option for clearer iden­ti­fi­ca­tion, such as the name of the ap­pli­ca­tion appearing on the task bar. I suspect more use of Windows 7 will result in a change in my ex­pec­ta­tion for this aspect of task bar operation.

IE 8 rendering issues

There is a still a lot of work to do here. I suspect that a lot of people will enable com­pat­i­bil­i­ty mode to enable sites to load. One site with problems was GMail (I'm using Google Apps for e-mail).

Tagged with internet-explorer, task-bar, dell, geforce, nvidia, review, windows and windows7.

Computer running slow after installing Antivirus software?

Almost everyone I know complains about the per­for­mance of their computer when an anti-virus (A/V) product has installed, and thinks they need more memory or a faster processor. Wrong! You need to get a faster hard disk, or disable scanning of certain files.

You'll see from Task Manager that memory and other resources are plentiful on a modern computer, but page faults and other disk I/O (hidden by default) are occurring at very high levels. Disk I/O is still slow on modern computers and you'll get better per­for­mance gains from improving this aspect.

Most A/V software has settings that let you control:

  • Scanning inside archives like .zip files. Only files downloaded from the Internet or via other media are major threats. Consider tweaking these settings to avoid scanning too deeply into archives, or only scan in risky locations (external drives or downloads folder).
  • Di­rec­to­ries that excluded from automatic scanning. Real-time protection is valuable for certain users, but there may be files that a user must access very frequently. These include databases or virtual machines. Consider disabling real-time scanning of these files/folders.
Making changes to these settings will benefit per­for­mance, and security can still be maintained to a very high level. You are running Windows under a normal user account, aren't you?

Tagged with antivirus, performance and windows.

Relog Utility

Relog.exe isn't some new fad amongst Bloggers - it's a tool from the Windows Resource Kit that helps you convert per­for­mance counter logs produced by Per­for­mance Monitor (perfmon.exe) into common text formats such as CSV. Earlier today I ran perfmon.exe and forgot to change the logging format from the default binary format to CSV. I searched the Web for a tool to convert to a format acceptable to LogParser and I found Relog. This utility saved me having to redo five hours of monitoring to get the data that I needed to analyse. Cheers to the Resource Kit team!

Syntax: relog input.blg -f CSV -o output.csv

Where can I get it? Download relog.exe for free from the Microsoft Download Center (requires a genuine Windows in­stal­la­tion).

Tagged with perfmon and windows.

Review of Protect Your Windows Network : From Perimeter to Data

Protect Your Windows Network : From Perimeter to Data, by Jesper M. Johansson, Steve RileyWhen I attended TechEd Europe in July 2002 one of the most in­ter­est­ing sessions was presented by Steve Riley. This was an overflow session presented during lunch, and I thought it would be in­ter­est­ing to check out something I hadn't planned to look at. The session covered use of IPSec, and the pre­sen­ta­tion style was very engaging. Rather than discuss technology in search of a solution, Steve solicited a number of scenarios from the audience and presented the hidden power of IPSec.

Many years pass, and I spot a blog entry from Jesper Johansson, where he book that is co-authored with Steve. I ordered it almost im­me­di­ate­ly from and I wasn't let down. This book is a gem for any developer who is trying to understand in­fra­struc­ture security and the ca­pa­bil­i­ties of the Windows platform. It's a fairly easy read and only delves into the necessary detail, avoiding coverage of mundane technical details that are presented on TechNet. To get the most out of this book you'll want your own test rig set up on vir­tu­alised hardware (think VMWare or Virtual Server) with a domain controller, cer­tifi­cate services, ISA Server and the like.

It's really hard to fault this book, maybe it should be available in hardback?

Tagged with security and windows.

Crash reporting in Windows

Microsoft have been collecting crash data using a system known as Windows Error Reporting ("Dr Watson") since the release of Windows XP (and possibly earlier). When a usermode error occurs in an ap­pli­ca­tion, a minidump and other pertinent is extracted. The user is then prompted as to whether they wish to report this in­for­ma­tion. After the reboot that follows a kernal mode error (bugcheck) you are prompted to send this in­for­ma­tion to a secure Microsoft server.

If the in­for­ma­tion is reported, a back end process does some analysis to see if it matches other error messages and might offer you some feedback. I've certainly benefited from this in the past, as a buggy D-Link driver caused numerous bugchecks (blue screens) and WER pointed me to a source of newer drivers.

I've observed the use of this feature by many people and there seems to be a fairly even split between those that send the crash data and those who cancel out. It appears that many people don't provide feedback because they fear Microsoft getting getting access to private in­for­ma­tion. This fear is jus­ti­fi­able, but I think that Microsoft could encourage more people to submit bug reports if they improved their UI design and branding.

The current im­ple­men­ta­tion on Windows XP and 2003 has these faults:

  • The UI is simplistic. Although it offers some in­for­ma­tion on why you might submit, it fails to reinforce the benefits.
  • Technical in­for­ma­tion cannot be easily copied to the clipboard. It would also be good to be able to save this to a file.
  • There is little help provided to help decipher the technical in­for­ma­tion provided.
  • Lack of Windows UI in­te­gra­tion. If you are using a shared computer, an ad­min­is­tra­tor cannot see all of the issues which have been submitted to spot problem ap­pli­ca­tions. The settings for crash reporting are hidden away from most users in the system applet.
  • If you are offline you cannot submit a report.
Thankfully there are some im­prove­ments on the way. Windows Vista will include support for cen­tralised crash reporting management, and improved UI. I will post a review of this in Beta 2 soon. Users of Office 2007 will notice that the bug and usage data collector is more advanced, and allows you to submit later. This is enabled when you sign up for the ap­pli­ca­tion im­prove­ment programme when prompted in the task no­ti­fi­ca­tion area.

Tagged with debugging, error-handling and windows.