Virtual function TWindow::GetClassName has return type LPCTSTR (or LPTSTR in OWL5_COMPAT mode). However, it may not return a valid string, and in this case, using the return value as a string will lead to a crash (access violation). This can lead, and has led, to bugs. For example, see [bugs:#340].
The problem is that a window class name, as defined by Windows, is a special union type. Although it masquerades as a string pointer, it can also be an atom. The Windows documentation for WNDCLASS.lpszClassName (msdn.microsoft.com) states:
"A pointer to a null-terminated string or is an atom. If this parameter is an atom, it must be a class atom created by a previous call to the RegisterClass or RegisterClassEx function. The atom must be in the low-order word of lpszClassName; the high-order word must be zero."
For more about atoms, see About Atom Tables.
Create an abstraction for class names, TWindowClassName, that encapsulates the dual nature of class names, similar to the class TResId. Rename TWindow::GetClassName to GetWindowClassName, and change the return type to TWindowClassName.
Bugs: #340
Discussion: Warning Destroying from TWindow::~TWindow
Feature Requests: #170
Wiki: Upgrading_from_OWL
The proposed solution has now been implemented on the Owlet branch. The new class TWindowClassName, defined in "owl/module.h", encapsulates a window class name. TWindow::GetClassName has been renamed to GetWindowClassName and the return type has been changed to TWindowClassName, as have the class name parameter for TModule::GetClassInfo.
See [r3482], [r3483] and [r3489]-[r3493].
Related
Commit: [r3482]
Commit: [r3483]
Commit: [r3489]
Commit: [r3493]
Last edit: Vidar Hasfjord 2016-09-06
The solution on the Owlet branch has now been merged into the trunk [r3497]. An addition, a new dummy-declaration of the now obsolete virtual function TWindow::GetClassName has been added [r3498], to prevent accidental non-overriding virtual functions in derived classes. Trying to override this dummy will cause a compilation error, forcing the the user to change the code to override the new function GetWindowClassName instead.
Edit: The implementation of TWindowClassName::GetString was missing in merge [r3497]. This has now been fixed in [r5304].
Related
Commit: [r3497]
Commit: [r3498]
Commit: [r5304]
Last edit: Vidar Hasfjord 2020-12-08
Diff: