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
1
vote
1 answer

Check if the TCHAR array input is signed integer C++

I have an TCHAR array in as follows, TCHAR input[MAX_PATH] = L"12345"; I want to check whether input TCHAR array is valid signed integer or not? These are the some examples for it and output should be as follows, L"123-" -> false L"123" ->…
1
vote
1 answer

How to convert TCHAR to const char?

The most similar thing I found is conversion to char. I'm trying to convert TCHAR "path" to const char. Btw I use character set: "Not Set". #include // ... your defines #define MAX_LEN 100 TCHAR *systemDrive =…
Pranciskus
  • 487
  • 1
  • 6
  • 17
1
vote
1 answer

cannot convert from 'unsigned short [9]' to 'char []'

I am working on very old C++ project. When building my C++ code in Visual Studio 6 I am getting error "cannot convert from 'unsigned short [9]' to 'char []'". for code below: char variable[] = _T("something"); I googled and tried to understand…
1
vote
2 answers

Re-'new' TCHAR* array

will a re-new of a TCHAR* array has negative/undefined effect? Or even maybe not recommended? Below code has been working fine so far. Need inputs. Thanks! //e.g. TCHAR *tc1 = new TCHAR[1]; // later: //resize TCHARs tc1 = new…
jude
  • 51
  • 1
  • 9
1
vote
0 answers

How concatenate a TCHAR array to left side?

I want concat the string -jar to left side of a path the is C:\Users\NZT48\AppData\Roaming where final result must be like: -jar C:\Users\NZT48\AppData\Roaming Have tried with code below, but when concatenates the path with the string -jar is…
user7649139
1
vote
3 answers

Use TCHAR in ostringstream

Okay, I'm not really a C++ person, and this will probably be downvoted to damnation as I am just reading the code and making guesses based of the other languages I know (bad I know, but I just want to compile one solution with a small…
Alice
  • 422
  • 1
  • 9
  • 28
1
vote
2 answers

C++ TCHAR[] to string

I have this method which receives a path through a TCHAR szFileName[] variable, which contains something like C:\app\...\Failed\ I'd like to sort through it so I can verify if the name of the last folder on that path is in fact, "Failed" I thought…
hikizume
  • 578
  • 11
  • 25
1
vote
1 answer

copy file to windir c

I need to copy one file to windir, So I do: TCHAR windir[MAX_PATH]; GetWindowsDirectory(windir, MAX_PATH); to get the windir. char newLocation[]="text.txt"; // how to add the windir here? BOOL stats=0; CopyFile(filename, newLocation, stats); My…
RGS
  • 4,062
  • 4
  • 31
  • 67
1
vote
2 answers

C++ _findfirst and TCHAR

I've been given the following code: int _tmain(int argc, _TCHAR* argv[]) { _finddata_t dirEntry; intptr_t dirHandle; dirHandle = _findfirst("C:/*", &dirEntry); int res = (int)dirHandle; while(res != -1) { cout <<…
Arrrow
  • 542
  • 5
  • 21
1
vote
5 answers

Visual Studio 2015 WinAPI error on MessageBox

I created a basic Windows C++ application in Visual Studio 2015 and I have a few errors: #include #include #include #include int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR…
Vento
  • 37
  • 3
  • 9
1
vote
4 answers

Sending TCHAR buffer with send(sock, wszBuffer, ...)?

I have a wide-character XML message that I need to send over a Win32 socket in C++. TCHAR wszBuffer[1024]; Should I sprintf(szSendBuffer, "%S", wszBuffer) the wide character buffer to a char array before sending it? What is the correct way to send…
Petrus Theron
  • 27,855
  • 36
  • 153
  • 287
1
vote
2 answers

win32 c++ fstream wide argument

See link for what I'm talking about. I want to use point 1 in the link and #define tfopen _wfopen #define _T(s) L##s to do exactly what the link says is possible: std::ifstream file( tfopen("filename.txt", _T("r") ); But gcc (mingw) 4.4 says…
rubenvb
  • 74,642
  • 33
  • 187
  • 332
1
vote
0 answers

How to convert between UTF-8 and TCHAR generically

I know I've seen this on the web, but when I searched for it I only found this example. However that code is only valid if UNICODE is defined, the one I thought I saw had conditionals for when UNICODE was not defined (and I think it had a third case…
skyking
  • 13,817
  • 1
  • 35
  • 57
1
vote
1 answer

What is the size of a Word in the context of the mbstowcs_s function SizeInWords parameter?

I am having difficulty determining what the exact size of a Word should be in the context of the Windows API function mbstowcs_s. Here is the relevant information from the MSDN as well as the link. mbstowcs_s, _mbstowcs_s_l Converts a sequence of…
HighExodus
  • 104
  • 2
  • 11
1
vote
2 answers

Flexible string handling in Visual Studio 2008 C++

I'm slowly starting to get the hang of the _T stuff in Visual Studio 2008 c++, but a few things still elude me. I can see the benefit of the flexibility, but if I can't get the basics soon, I think I'll go back to the standard way of doing this -…
David
  • 17
  • 1
  • 3