Other Projects

HTTP Live Streaming (HLS) for Windows Phone: http://phonesm.codeplex.com/ or on GitHub

More projects can be found on GitHub.

PasswordSafe for Vista x64

The 3.10 release of PasswordSafe requires double-clicking to expand or collapse groups on Vista x64. Looking at the source to see if there was some obvious solution, it struck me as a reasonable test case of just how difficult it would be to migrate a non-trivial Win32 MFC application to 64-bit mode. This was somewhat more work that I had anticipated. The result seems to interoperate with the official 3.10 binary under Vista x64, but the port is by no means polished.

I enabled precompiled headers for everything partly because builds are much faster, but also because there was a conflict between libcpmt and some other libraries (due to only some files including the MFC headers).

The _USE_32BIT_TIME_T work-around is not available for x64 builds, so serialization and deserialization code referencing time_t needed some changes.

The manifest can be handled by the compiler/linker (and some gunk in stdafx.h). Needless to say, putting “x86” in a 64-bit application's manifest makes the loader unhappy. It also appears that the explicit Common Controls dependency caused the group expand/collapse issue.

A patch was generated against SVN r1665: pwsafe_20070904.diff.gz

dSFMT Wrapper for .NET 2.0

Source (VS2005 Solution): RandomSFMT_20070928.zip

Binaries: RandomSFMT-bin_20070928.zip

The default random number generator class (System.Random) is based on a simple but decent random number generator. Makoto Matumoto's Mersenne Twister is a more modern generator. On a Vista Business x64 system with a Core 2 Duo T7500, the SIMD variant is approximately twice as fast as System.Random for generating double-precision random numbers over [0, 1) (equivalent to System.Random's NextDouble()).

Note that neither System.Random nor dSFMT should be used for cryptographic purposes; use a generator designed for that sort of thing such as RNGCryptoServiceProvider or as described in NIST SP 800-90. Be aware that cryptographic generators tend to be much slower than their non-cryptographic counterparts.

This implementation wraps the reference “C” implementation from dSFMT-src-1.2.1.zip in a .NET 2.0 assembly. It always uses SFMT_N64 integers from RNGCryptoServiceProvider to seed the generator. Since the reference code only supports one instance of the generator, the wrapper object uses a local buffer and only locks the shared generator when this buffer is empty. The local buffer also reduces the number of managed/unmanaged transitions. SSE2 instructions are used when available on x86 and are always used when run in x64/AMD64 mode.

It seems Microsoft has gone out of their way to make it difficult to build applications that contain both x86 and x64/AMD64 code without using the GAC. This implementation uses an AppDomain.AssemblyResolve handler to redirect failed assembly loads to architecture-specific directories (there are examples for both WPF in C# and Windows Forms in Visual Basic).

One lesson learned the “fun” way from this little project is that .NET does not keep doubles aligned on 8-byte boundaries (see dSFMT_Generator.cpp for one way to deal with this).