_T Macro Question

This is a discussion on _T Macro Question within the Windows Programming forums, part of the Platform Specific Boards category; I am new to MFC programming.
How do you display variables using a _T macro
Code:
void CMainWindow::OnLButtonDown(UINT nFlags, CPoint ...

When I am doing MFC programming (as opposed to API programming) I always use CString. It is an efficent class in terms of memory management, and all the string manipulation and conversion functions are already written (so you don't need to reinvent the wheel).

you dont want to use wsprintf, because what if _UNICODE isn't defined? The correct way would be to use a tchar.h routine like _stprintf().

Are you confusing wsprintf (Windows sprintf) with swprintf? Anyway _stprintf is often a better choice as wsprintf provides only a subset of the functionality of _stprintf. For example, it does not support floating point values and has a short maximum buffer length. wsprintf depends on whether UNICODE is defined while _stprintf depends on whether _UNICODE is defined. You should always have both of these symbols defined, or neither.

Are you confusing wsprintf (Windows sprintf) with swprintf? Anyway _stprintf is often a better choice as wsprintf provides only a subset of the functionality of _stprintf. For example, it does not support floating point values and has a short maximum buffer length. wsprintf depends on whether UNICODE is defined while _stprintf depends on whether _UNICODE is defined. You should always have both of these symbols defined, or neither.

I don't do much mfc but I assume that if you define the unicode macros for your project, that should be good enough. Hopefully someone with considerably more than my next-to-none mfc experience will clarify this for you shortly.

tchar.h (again, open it up and take a look) defines a bunch of unicode/non-unicode mappings for mainly string functions and the _T and TEXT macros (these latter two are also defined elsewhere, maybe winnt.h) so you should only include it if you need to. If you're using wsprintf, you won't need tchar.h because wsprintf is an api and should be available for you to use without any extra header includes.

Actually, if you're using mfc just use the mfc cstring class (rog mentioned this already).