Socket SendString (C++) w/ TCHAR


I need to send a unicode string (e.g TCHAR *ptr) but the API only allows to send char.


The _TCHAR data type is defined conditionally in Tchar.h. 
If the symbol _UNICODE is defined for your build, _TCHAR is defined as wchar_t; 
otherwise, for single-byte and MBCS builds, it is defined as char.
bool sendString(CkSocket &sock, TCHAR *str)
    bool success = false;

#ifdef _UNICODE
    success = sock.SendBytes((const unsigned char *)str, _tcslen(str) * 2);
    success = sock.SendString(str);

    return success;
Tags :