Windows API and GetClassName ()? Another name?

I have code that has a dynamic class system in C ++ that has a member called GetClassName (), a pretty innocuous name that you can imagine. However, when he was involved in a large project with Windows titles, all hell broke. Windows seems to be using #define GetClassName (GetClassNameA or GetClassNameW) which screwed everything up and my virtual call tree got corrupted, causing me to lose a day in a silly debug compilation in the dark, trying to figure out what was wrong.

So, except that I curse Microsoft for using such a terribly easy name clash for #define (I mean, someone must honestly be shot for it!) I ask for three goals.

  • What is another good name for GetClassName ()?
  • Is there any way to fix this, so that in the future other developers of my code base will not suffer a similar fate.
  • And for posterity, when someone else encounters this similarly unexplained error
+3
source share
4 answers

I would rename the method.

Of course you can say

#include <windows.h>
#undef GetClassName

but it is not clean, users of the same code should remember the :: GetClassNameW entry when they call the win32 function.

You can provide GetClassNameA and GetClassNameW methods in your class, but this is pretty ugly.

I see two approaches: lengthen or shorten the name :)

1) add a prefix for all functions in the subsystem, fe TI_ (for type information):

TI_GetClassName() 
TI_GetBaseClass() 
TI_IsDerivedFromClass()
etc  

2) or put them in some iClass interface

interface IClass {
GetName();
GetBase(); 
IsDerivedFrom();
etc

,
GetClassName()

GetClass()->GetName()
+2
  • ClassGetName()
  • #undef GetClassName
  • WinAPI - API C. . , . : , SDK Windows Platform, #include .
+5

, GetWindowClassName? GetClassName API, . , API C C , .

, C, Microsoft.

+2

API Windows , , ASCII/UTF-16, . , "W32" (a la "NS" OS X), , API "".

, API, :

1) Windows API ( !) , , MSDN, , .

2) , (MyClass:: GetClassName()). , , .

3) . MS CamelCase, , (get_class_name(), getClassName() ..).

4) "GetX()" "SetX()", "xtype X() const" "void X ( xtype newval)" . , , get/set - . , , .

!

+2

Source: https://habr.com/ru/post/1703712/


All Articles