The Return of the Class Wizard

January 24, 2010

Visual C++ 6 aficionados remember (fondly) the Class Wizard, most useful in MFC applications. The Class Wizard has gone away in later version of Visual Studio (2002, 2003, 2005, 2008), but is now making a smashing return in Visual Studio 2010 (Project menu –> Class Wizard or Ctrl+Shift+X). This has the familiar options (relative to VC++ 6), such as adding/removing message handlers, command and update command handlers, creating new classes, member variables, etc. There are new options, such as creating custom message handlers and the ability to search. In my experience, many developers back...
no comments

Gotcha: CreateProcess causes Access Violation

January 17, 2010

The famous CreateProcess function may fail with an access violation. For example, this innocent looking code causes a crash: STARTUPINFO si = { sizeof(si) }; PROCESS_INFORMATION pi;   CreateProcess(0, _T("notepad"), 0, 0, FALSE,     0, 0, 0, &si, &pi); What’s wrong with this code? Apparently nothing. The key here is that CreateProcess is not actually a function at all, but a macro that’s expanded to CreateProcessA or CreateProcessW depending a compile time constant (UNICODE). If we open...
5 comments

WeakReferences and Events

January 7, 2010

One of the well-known pitfalls of using events, is the holding of the subscriber instance by the publisher (if connecting to a delegate holding an instance method). If the subscriber forgets to unsubscribe, the instance cannot be garbage collected because the publisher holds a reference to it. Worse yet, the subscriber continues to receive event notifications even though it’s not interested. One way to deal with this is presented in Jeffrey Richter’s book “CLR via C#”. The idea is based on a custom event implementation holding a list of WeakReference objects to the incoming subscribers delegates: ...
tags: , , ,
one comment