Projects in Visual C++ 2010 – Part 1: Creating a DLL project

When you write software, you often/sometimes divide your project into several subprojects. This mini series describes how to do this with Visual C++ 2010 (but this first part also applies to earlier versions). We start with creating a library project in form of a DLL.

Related articles:

Read more →

Mutexes in .NET

The Mutex class in .NET is a little bit tricky to use.

Here’s an example how I got it to do what I want:

/// <summary>
/// A simple, cross application mutex. Use <see cref="Acquire"/> to acquire it
/// and release it via <see cref="Dispose"/> when you're finished.
/// </summary>
/// <remarks>
/// Only one thread (and thus process) can have the mutex acquired at the same
/// time.
/// </remarks>
public class SimpleMutex : IDisposable
    private readonly Mutex m_mutex;

    /// <summary>
    /// Acquires the mutex with the specified name.
    /// </summary>
    /// <param name="mutexName">the mutex's name</param>
    /// <param name="timeout">how long to try to acquire the mutex</param>
    /// <returns>Returns the mutex or <c>null</c>, if the mutex couldn't be
    /// acquire in time (i.e. the current mutex holder didn't release it in
    /// time).</returns>
    public static SimpleMutex Acquire(string mutexName, TimeSpan timeout)
        var mutex = new SimpleMutex(mutexName);
            if (!mutex.m_mutex.WaitOne(timeout))
                // We could not acquire the mutex in time.
                return null;
        catch (AbandonedMutexException ex)
            // We now own this mutex. The previous owner didn't
            // release it properly, though.

        return mutex;

    private SimpleMutex(string mutexName)
        this.m_mutex = new Mutex(false, mutexName);

    public void Dispose()

You can use it like this:

using (SimpleMutex.Acquire("MyTestMutex", Timeout.InfiniteTimeSpan))
    Console.WriteLine("Acquired mutext");

Console.WriteLine("Released mutext");

If you run your program twice, one will acquire the mutex and the other one will wait – until you press a key in the first one.

Note: If you forget to call Dispose() on this mutex, the operating system will make sure that the mutex is released when the program terminates. However, the next process trying to acquire this mutex will then get an AbandonedMutexException (which is handled properly in Acquire() though).

Windows Performance Counter Types

There are several types of performance counters in Windows. However, I had a hard time of understanding all these types just from their documentation. So I decided to compile some examples for each counter type.

I also wrote some C# code to demonstrate how to use performance counters. You’ll find it at the end of this article.

Read more →

Updating MAMP


Working with MAMP is quite easy. However, the process of updating MAMP to a newer version might contain some uncertainties.

The following table contains things that one want to keep when upgrading to a newer version and whether they’re correctly migrated or not.

What Migrated
server ports (as specified in settings) no (tracked as #4796)
htdocs directory yes (moved)
htdocs location (as specified in settings) no (tracked as #4796)
Databases (db directory) yes (moved)

The process was tested with MAMP

.NET Serializers Comparison Chart

There are many object serializers in C#/.NET but their details are often not so obvious, for example:

  • Does my class need a parameterless constructor?
  • Can I serialize private fields?
  • Can I serialize readonly fields?

So, I’ve compiled a comparison chart in this article that will compare the various serializers and their capabilities.

Read more →