Skip to content

Instantly share code, notes, and snippets.

@RyanJeong
Last active January 28, 2024 14:53
Show Gist options
  • Save RyanJeong/04a4b92879ab10edfd9656d0aa4f3b77 to your computer and use it in GitHub Desktop.
Save RyanJeong/04a4b92879ab10edfd9656d0aa4f3b77 to your computer and use it in GitHub Desktop.
A way to convert char[] to/from TCHAR[] in C/C++(WinAPI)

TCHAR -> char

#define SIZE 1024

TCHAR src[SIZE] = L"This string will be char type";
char  dest[SIZE];

WideCharToMultiByte(CP_ACP, 0, src, lstrlen(src), dest, SIZE, NULL, NULL);

char -> TCHAR

#define SIZE 1024

char  src[SIZE]		= "This string will be TCHAR type";
TCHAR dest[SIZE]	= {0, };

MultiByteToWideChar(CP_ACP, MB_PRECOMPOSED, src, strlen(src), dest, SIZE);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment