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
2
votes
2 answers

proper style for interfacing with legacy TCHAR code

I'm modifying someone else's code which uses TCHAR extensively. Is it better form to just use std::wstring in my code? wstring should be equivalent to TString on widechar platforms so I don't see an issue. The rationale being, its easier to use a…
Dustin Getz
  • 21,282
  • 15
  • 82
  • 131
2
votes
1 answer

StringCbPrintf Example Not Working

Using Multibyte character set in building the example from MSDN we get the "initializer is not a constant" error for the last line. VS10 SP1, no CLR. #define arraysize 30 TCHAR pszDest[arraysize]; size_t cbDest = arraysize *…
Laurie Stearn
  • 959
  • 1
  • 13
  • 34
2
votes
4 answers

Concatenating strings of different types in C++

How can I concatenate the following char and TCHAR variables in C++? TCHAR fileName[50]; TCHAR prefix[5] = "file_"; TCHAR ext[4] = ".csv"; char *id[10]; generateId(*id); The generateId(char *s) function simply generates a random string. I need to…
matt
  • 2,312
  • 5
  • 34
  • 57
2
votes
1 answer

Weird characters in a std::vector

Trying to get all sub directories, and eventually all files in sub directories, and I'm passing a std::vector as a reference to a function that actually gets all of the directories. I can cout the cFileName inside the function but once it returns…
Siver
  • 67
  • 1
  • 11
2
votes
2 answers

tchar safe functions -- count parameter for UTF-8 constants

I'm porting a library from char to TCHAR. the count parameter of this fragment, according to MSDN, is the number of multibyte characters, not the number of bytes. so, did I get this right? My project properties in VC9 say 'use unicode character set'…
Dustin Getz
  • 21,282
  • 15
  • 82
  • 131
2
votes
1 answer

C++ LoadLibrary Not working

if (LoadLibrary(L"d:\\cwebpage.dll")) MessageBox(0, L"Loaded", L"ERROR", MB_OK); else MessageBox(0, L"Error", L"ERROR", MB_OK); Its not working, I have tried if (LoadLibrary(_T("d:\\cwebpage.dll"))) //#include if…
Wasim A.
  • 9,660
  • 22
  • 90
  • 120
2
votes
5 answers

C++ windows how to convert 'unsigned int' to 'TCHAR *'?

I am in new to C++ on windows. Can you please tell me how to convert unsigned int to TCHAR *?
Gana
  • 979
  • 3
  • 10
  • 18
2
votes
1 answer

How am I using CA2W incorrectly?

Please could someone explain why this does not work? char *test = "test"; _TCHAR *szTest = CA2W(test); And please tell me what I should be doing instead. Instead of giving me equal text, it's giving me: ﻾﻾﻾﻾﻾﻾﻾﻾﻾﻾﻾﻾﻾﻾﻾﻾﻾﻾﻾﻾﻾﻾﻾﻾﻾﻾﻾﻾﻾﻾﻾﻾
Nick Bolton
  • 38,276
  • 70
  • 174
  • 242
2
votes
2 answers

How to disable Microsoft's decorations of tchar.h in Visual Studio?

By default Microsoft's Visual Studio is using and defines main as int _tmain(int argc, _TCHAR* argv[]). This can be usefull but not always. How to disable this in default new project? UPDATE I want to create empty projects with simple…
Suzan Cioc
  • 29,281
  • 63
  • 213
  • 385
1
vote
1 answer

Why address difference between Unicode is incorrect here?

Look at the code below, #include #include int main() { TCHAR szStr[] = TEXT("C++中文你好"); printf("sizeof(szStr) = %u\n", sizeof(szStr)); //16 LPTSTR lp = _tcschr(szStr, TEXT('好')); _tprintf(TEXT("szStr = %p, lp = %p…
SZYoo
  • 147
  • 7
1
vote
2 answers

TCHAR is used in Win32 api .But It is enough to use char or string there.But why TCHAR?

I am learning about win32 api .The TCHAR datatype is used in it for defining stings that are used for registering the class.Why is TCHAR used there?
Abhiram
  • 7
  • 2
1
vote
2 answers

What is TCHAR and how does it differ from WCHAR?

This question should've had an answer nowadays here, but there is nothing explaining what exactly TCHAR is on stackoverflow (all I found is an explanation of the difference between TCHAR and _TCHAR). All I know is that TCHAR and _TCHAR are…
Kaiyaha
  • 448
  • 3
  • 9
1
vote
1 answer

C++ TEXT macro of TCHAR*

I am trying to create a TCHAR* variable by using TCHAR* example = TEXT("example"); but it wont even compile and says: A value of type const wchar_t* cannot be used to initialize an entity of type TCHAR*. What should I do?
Mary
  • 63
  • 4
1
vote
2 answers

C++ Microsoft example to get and display the user name doesn't compile

I want to get the user name in C++ in the most easiest way. My program is only designed for Windows. I would like to use the Microsoft example. I copy paste the code example in a fresh Visual Studio 2019 but I have errors on TEXT instruction: a…
user13339912
1
vote
2 answers

Why error C6386 buffer overrun with strsafe.h StringCch functions?

So I ran an Analyze in VS 2017 with my C++ code. It gives me a buffer overrun with the following: TCHAR *sTemp = new TCHAR[5](); if (sTemp) StringCchCopy(sTemp, 5, L"0123456789"); When I step through the code, sTemp is "0123", with the 4th…
JeffR
  • 765
  • 2
  • 8
  • 23