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
0
votes
1 answer

Why is it necessary to null-terminate a TCHAR array when enumerating registry values in a for loop?

I've been following MSDN's example on enumerating registry subkeys. http://msdn.microsoft.com/en-us/library/windows/desktop/ms724256%28v=vs.85%29.aspx In the following code, I don't understand why achValue[0] = '\0'; is necessary. I ran some tests…
Hugh McMaster
  • 319
  • 3
  • 10
0
votes
1 answer

Can't pass argv into a string in one project; Works fine in another

I have two c++ win32 console application project. Both have exactly identical code. #include "stdafx.h" #include #include #include #include using namespace std; int _tmain(int argc, _TCHAR* argv[]) { …
0
votes
1 answer

size of TCHAR array in DWORD

I have following VC++ code. How to clalculate size of TCHAR in DWORD which will not fail at runtime. HKEY hKey = 0; DWORD dwType = REG_SZ; TCHAR buf[255] = {0}; DWORD dwBufSize = sizeof(buf); if( RegOpenKeyEx( HKEY_LOCAL_MACHINE,…
user1833852
  • 51
  • 2
  • 10
0
votes
0 answers

How do I convert from wstring (that's subst'ed) to TCHAR?

I have a wstring that I assign in the following function. I pull out of the string with the .substr method with the start and length parameters. But once I do a substr, how do I get the result ultimately into a TCHAR that the function can return…
JeffR
  • 765
  • 2
  • 8
  • 23
0
votes
1 answer

System::String^ to TCHAR*

I have a class which collects all paths to .txt files of a given folder and stores them into a vector. Most of the functions I use require the usage of TCHAR* to get/set current directory and so on. The class looks like this: typedef…
Edd
  • 1,982
  • 2
  • 21
  • 29
0
votes
1 answer

Getting process ID's

My program below will concatenate the names of the processes into the names string. How can I change it to include the process ID's instead of names? What type should names be, how to initialise it and how to concatenate every proc32.th32ProcessID…
George Irimiciuc
  • 4,573
  • 8
  • 44
  • 88
0
votes
1 answer

WCSLEN doesnt work correctly

I've got some code int _tmain(int argc, _TCHAR* argv[]) { HANDLE hFile; DWORD dwRWBytes; TCHAR frmdata1[] = _T("-----------------------------7d82751e2bc0858\r\nContent-Disposition: form-data; name=\"file\";…
user3416803
  • 379
  • 1
  • 2
  • 12
0
votes
5 answers

TCHAR[], LPWSTR, LPTSTR and GetWindow Text function

So the GetWindowText is declared on MSDN as follows: int GetWindowText( HWND hWnd, LPTSTR lpString, int nMaxCount ); However for the code to work we have to declare the second parameter as TCHAR[255] WTitle; and then call the…
lhj7362
  • 2,173
  • 4
  • 19
  • 17
0
votes
1 answer

how to add formatted string (for multiple filenames etc.) in tchar

Like in win32 C++ we use to use following code if needed to add multiple files as file_name0.txt, filename1.txt, ...., filename30.txt etc. char fname[20]; for i = 0 -> 30 { sprintf(fname, "filename%d.txt", i); } How can we do the same with TChar…
SJa
  • 487
  • 4
  • 14
0
votes
0 answers

input doesnt read spaces(_tscanf_s and wcscpy_s)

This is my code, _tprintf(_T("\nPlease set all fields")); _tprintf(_T("\n Input Name: ")); _tscanf_s(L"%ls",inputHolder,length); wcscpy_s(LC.NAME,length, inputHolder); the problem is when I am inputting a name with space the program will think…
0
votes
1 answer

Runtime check failure in CString destructor caused by setting Class ptr to NULL?

so somewhere along the lines of putting this app together I've started to get a runtime check failure stack corruption when the destructor for a cstring class member is called. I've gotten to the point of trying to debug this by throwing bricks at…
Himilou
  • 127
  • 10
0
votes
2 answers

How to replace character in TCHAR string

I have a TCHAR string which contains a path. I need to replace all occurences, if any, of / with \ in the path. The variable holding the path is defined as follows: TCHAR mypath[1024]; If mypath contains C:/new/newfile/a.txt, then I would need the…
SoDa
  • 71
  • 2
  • 8
0
votes
1 answer

C++ _TCHAR* to std::string

I created a project in C++, and VS2010 created int _tmain(int argc, _TCHAR* argv[]) { string sInput; string sOutput; int iMode=0; if (argc==3) { if (strcmp(argv[0], "-e")==0) { iMode = 1; } else if (strcmp(argv[0],…
tmighty
  • 10,734
  • 21
  • 104
  • 218
0
votes
1 answer

Qt cannot convert 'const wchar_t*' to 'TCHAR*'

I transfer the project from visual studio to QT and when the project build - displayed errors. How to fix them without making significant changes in the code?. cannot convert 'const wchar_t*' to 'TCHAR*' cannot convert '_TCHAR*' to 'const…
Dmitriy
  • 161
  • 2
  • 12
0
votes
2 answers

C++ TCHAR array to wstring not working in VS2010

I would like to convert a TCHAR array to a wstring. TCHAR szFileName[MAX_PATH+1]; #ifdef _DEBUG std::string str="m:\\compiled\\data.dat"; TCHAR *param=new TCHAR[str.size()+1]; szFileName[str.size()]=0; …
tmighty
  • 10,734
  • 21
  • 104
  • 218
1 2 3
10
11