Misleading Error: "Parent class code is read only" (Visual Studio.NET)

2004-01-29 21:09:00 +0000

I just had a strange error message from Visual Studio.NET when attempting to add a handler for WM_DESTROY to a C++ dialog class. It said:

Add/Remove of the function is impossible because the parent class code is read only

Odd. There’s nothing read-only about any of this stuff.

It turns out that I’d previously had an OnDestroy function in that class, and (somehow) the ON_WM_DESTROY() macro had been left in the message map. This apparently confuses Visual Studio.

Just remove the old ON_WM_DESTROY() line, and it’s happy to add a new one.