Using strcpy_s for a TCHAR pointer (Microsoft Specific)

I was wondering what is the correct way?

_tcscpy(tchar_pointer, _tcslen(tchar_pointer), _T("Hello World"));

or

_tcscpy(tchar_pointer, _tcsclen(tchar_pointer), _T("Hello World"));

or

_tcscpy(tchar_pointer, ???, _T("Hello World"));
+5
source share
4 answers

the tchar pointer comes from the outside and my side doesn't know how big the buffer pointed by the pointer is

If so, then none of them will do what you want.

How all the "safe" functions work, you indicate how large the target buffer is.

You do not know? You cannot use these features.

int buffer_size = _tcslen(xxx) * sizeof(TCHAR)

. , , , . , ; '\0', ; ..

+6

, _tcscpy_s, _tcscpy, , . :

TCHAR dest[20];
_tcscpy_s(dest, _countof(dest), _T("Hello"));

, :

_tcscpy_s(dest, _T("Hello"));

tchar_pointer , ( ), . , , .

+7

, . _tcslen _tcsclen, .

Unicode _tcslen _tcsclen TCHAR . TCHAR wchar_t.

_tcslen TCHAR . TCHAR char. _tcsclen . - TCHAR, - . , .

+3

tchar_pointer - ( ), , . , , strcpy_s .

+2

All Articles