I am compiling with -municode -DUNICODE -D_UNICODE flags and using _tmain to enable unicode support.
But when I perform operations on any TCHAR arrays containing unicode characters, the strings ends up truncated at wherever that character was.
For example:
TCHAR buffer[255];
wcscpy(buffer, L"test-");
wcscat(buffer, L"Азәрбајҹан");
/* buffer now contains "test-" */
My actual use-case is retrieving a username, which, if it contains special chars, will end up empty wether it's from GetEnvironmentVariable, GetUsername or even a hardcoded string like above.
EDIT:
Here is a complete minimal reproducible example:
Compiled with gcc -o error.exe error.c -municode under:
gcc.exe (Rev3, Built by MSYS2 project) 10.1.0
Copyright (C) 2020 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
Code:
#define _UNICODE
#define UNICODE
#include <tchar.h>
#include <stdio.h>
#include <stdlib.h>
int _tmain(int argc, TCHAR* argv[]) {
FILE* fp;
TCHAR buffer[255];
_tcscpy(buffer, _T("test-"));
_tcscat(buffer, _T("Азәрбајҹан"));
_tprintf(_T("Length: %d, Content: %ls\n"), _tcslen(buffer), buffer);
fp = _tfopen(_T("test.txt"), _T("w"));
_ftprintf(fp, _T("%ls"), buffer);
fclose(fp);
return 0;
}
This example prints 15 test- and puts test- into test.txt.

