Questions tagged [tchar]

A #define for either char or wchar_t, used for porting ancient windows applications

TCHAR and related preprocessor-defines are used in two places:

  1. Porting ancient windows application to modern UTF-16 APIs.
  2. Describing APIs available in both ANSI and UTF-16 flavor.

If neither of the above fits for you, you really should not be using it:
Is TCHAR still relevant?

#ifdef _UNICODE
    #define TCHAR wchar_t
    // many others
#else
    #define TCHAR char
    // many others
#endif
164 questions
3
votes
3 answers

Why do my Win32 API calls require the 'A' suffix and should I rectify that?

To execute a command from the Win shell I needed ShellExecuteA(NULL, "open", "http://stackoverflow.com", NULL, NULL, SW_SHOWNORMAL); and now I am working through Forgers Win32 Tutorial I am finding the A suffix necessary to prevent printing garbage…
John
  • 6,433
  • 7
  • 47
  • 82
3
votes
2 answers

Problem with tstring typedef

I am having a problem with trying to typedef myself a nice handy tstring (see below) #ifndef _NISAMPLECLIENT_H_ #define _NISAMPLECLIENT_H_ #include #include using namespace std; // ERROR here (1) #ifdef _UNICODE #define…
Dennis
  • 3,683
  • 1
  • 21
  • 43
3
votes
2 answers

error C2446: == : no conversion from const char * to TCHAR *

I have a TCHAR define below: TCHAR szProcessName[MAX_PATH] = TEXT(""); and I want to comapare as below: if(szProcessName == "NDSClient.exe") { } But then I am getting the errors: error C2446: == : no conversion from const char * to…
Simsons
  • 12,295
  • 42
  • 153
  • 269
3
votes
1 answer

Is there an official TCHAR type in C++ now?

If writing code which may be compiled with different character types, is TCHAR still the right type to use e.g std::basic_stringstream Or is there now some official C++/STL type which is preferred, in the way wchar_t replaces WCHAR, true…
Mr. Boy
  • 60,845
  • 93
  • 320
  • 589
3
votes
1 answer

What are TCHAR strings and the 'A' or 'W' version of Win32 API functions?

What are TCHAR strings, such as LPTSTR and LPCTSTR and how can I work with these? When I create a new project in Visual Studio it creates this code for me: #include int _tmain(int argc, _TCHAR* argv[]) { return 0; } How can I, for…
MicroVirus
  • 5,324
  • 2
  • 28
  • 53
3
votes
1 answer

How to convert TCHAR to double visual C++

I want to convert tchar* variable to double for my project. How can i do that? TCHAR *t = _T("1000.99");
Jamesfrank
  • 33
  • 4
3
votes
3 answers

Windows C++: LPCTSTR vs const TCHAR

In my application i'm declaring a string variable near the top of my code to define the name of my window class which I use in my calls to RegisterClassEx, CreateWindowEx etc.. Now, I know that an LPCTSTR is a typedef and will eventually follow down…
user353297
  • 736
  • 1
  • 7
  • 13
3
votes
4 answers

User defined conversion operator as argument for printf

I have a class that defined a user defined operator for a TCHAR*, like so CMyClass::operator const TCHAR*() const { // returns text as const TCHAR* } I want to be able to do something like CMyClass myClass; _tprintf(_T("%s"), myClass); or…
BC.
  • 33
  • 3
3
votes
2 answers

Converting string to tchar in VC++

how I can convert string to tchar in VC++? string internetprotocol="127.4.5.6"; TCHAR szProxyAddr[16]; i want to set: szProxyAddr=internetprotocol; how i can do it?
User123422
  • 889
  • 2
  • 11
  • 16
3
votes
2 answers

why TTN_NEEDTEXTW but not TTN_NEEDTEXTA?

This is an old problem that I've never figured out - wondered if someone here might happen to know the answer off of the top of your head... In some parts of our software (MFC/Win32/MBCS) my code will only receive TTN_NEEDTEXTW In other parts of our…
Mordachai
  • 9,412
  • 6
  • 60
  • 112
2
votes
2 answers

Why is PCTSTR not defined but LPCTSTR defined?

I have been assigned to update an old code written in MSVC++ 6. I have been getting unknown definition for PCTSTR but it was not defined even if I included the tchar.h. In my previous experience I know there is an LPTSTR but no PCTSTR. I grep the…
Nap
  • 8,096
  • 13
  • 74
  • 117
2
votes
5 answers

Why could i get an Unhandled exception Access violation writing in c++/CLI?

I have been struggeling writing a solution excisting out of an c++ win32console and a c++ dll. i finally managed to get them talking without linker errors (so i am assuming both are fully managed c++/CLI projects) but when i run the console i get…
Andy
  • 2,248
  • 7
  • 34
  • 57
2
votes
3 answers

How do you convert a 'System::String ^' to 'TCHAR'?

i asked a question here involving C++ and C# communicating. The problem got solved but led to a new problem. this returns a String (C#) return Marshal.PtrToStringAnsi(decryptsn(InpData)); this expects a TCHAR* (C++) lpAlpha2[0] =…
Andy
  • 2,248
  • 7
  • 34
  • 57
2
votes
3 answers

C++ tstring compare

I have this variable dirpath2 where I store the deepest directory name of a path: typedef std::basic_string tstring; tstring dirPath = destPath; tstring dirpath2 = dirPath.substr(destPathLenght - 7,destPathLenght - 1); I want to be able to…
hikizume
  • 578
  • 11
  • 25
2
votes
2 answers

Mapping format specifiers when Unicode is defined in C++?

Mapping format specifier %s to %ls when _tprintf() is mapped to wprintf()? I am using the _T() macro for mapping strings to either ASCII or Unicode, depending on whether _UNICODE is defined. However, a call like _tprintf("%s", _T("text string"))…
Shuzheng
  • 11,288
  • 20
  • 88
  • 186
1 2
3
10 11