views:

136

answers:

2

In C++ I have defined a class that has this as a member

static const std::basic_string<TCHAR> MyClass_;

There is also a getter function for this value

LPCTSTR CClass::GetMyClassName()
{
    return MyClass_.c_str();
}

When I create an instance of this class and then try and access it intellisense pops up but the name has been changed depending on whether the project has been compiled for Unicode or Multibyte. If it has been compiled for Unicode the function appears as.

aClass.GetMyClassNameW();

else it is

aClass.GetMyClassNameA();

What I'd like to know is how is the name getting changed? Also I would like to know is it possible for intellisense to show the correct name of the function? So that I can access it like this.

aClass.GetMyClassName()

EDIT: The precise member fucntion name i've used in my code is.

WinClass::GetClassName()
+9  A: 

Your method name is literally "GetMyClassName" or is it "GetClassName"?

GetClassName is in the SDK (winuser.h) and is redefined based on the UNICODE defines. If you are using "GetClassName" the intellisense is probably getting confused; in fact the compiler is generating the A/W suffix for the actual compiled method as well but that would all work because everyone (Linker/Compiler) agrees on the redefined name (even if its not visible).

Ruddy
Possible solutions should be changing the functions name or `#undef`-ing the macro.
Georg Fritzsche
You're right it is GetClassName(). Thank you so much that seems to be the reason it's doing that.
R. White
+1 for psychic debugging powers :)
Matteo Italia
+1  A: 

Thats the windows way to support in fact 2 versions of the Win32 API:

  • One for ascii characters of 1 byte with (char)
  • One for unicode with chars of typically 2 byte width (wchar)

If you look into i.e. winuser.h, you'll see the following:

WINUSERAPI
BOOL
WINAPI
SetWindowTextA(
    __in HWND hWnd,
    __in_opt LPCSTR lpString);
WINUSERAPI
BOOL
WINAPI
SetWindowTextW(
    __in HWND hWnd,
    __in_opt LPCWSTR lpString);
#ifdef UNICODE
#define SetWindowText  SetWindowTextW
#else
#define SetWindowText  SetWindowTextA
#endif // !UNICODE

I cant exactly tell why the same happens to your function GetMyClassName. But it pobably has the same reason.

RED SOFT ADAIR