{"id":248,"date":"2009-10-30T05:28:37","date_gmt":"2009-10-30T12:28:37","guid":{"rendered":"http:\/\/cknotes.com\/?p=248"},"modified":"2009-10-30T05:28:37","modified_gmt":"2009-10-30T12:28:37","slug":"socket-sendstring-c-w-tchar","status":"publish","type":"post","link":"https:\/\/cknotes.com\/socket-sendstring-c-w-tchar\/","title":{"rendered":"Socket SendString (C++) w\/ TCHAR"},"content":{"rendered":"<p><strong>Question:<\/strong><\/p>\n<p>I need to send a unicode string (e.g TCHAR *ptr) but the API only allows to  send char.<\/p>\n<p><strong>Answer:<\/strong><\/p>\n<pre>\r\n\/*\r\nThe _TCHAR data type is defined conditionally in Tchar.h. \r\nIf the symbol _UNICODE is defined for your build, _TCHAR is defined as wchar_t; \r\notherwise, for single-byte and MBCS builds, it is defined as char.\r\n*\/\r\nbool sendString(CkSocket &sock, TCHAR *str)\r\n    {\r\n    bool success = false;\r\n\r\n#ifdef _UNICODE\r\n    success = sock.SendBytes((const unsigned char *)str, _tcslen(str) * 2);\r\n#else\r\n    success = sock.SendString(str);\r\n#endif\r\n\r\n    return success;\r\n    }\r\n<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>Question: I need to send a unicode string (e.g TCHAR *ptr) but the API only allows to send char. Answer: \/* 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. [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[448,488,518],"class_list":["post-248","post","type-post","status-publish","format-standard","hentry","category-uncategorized","tag-c","tag-socket","tag-tchar"],"_links":{"self":[{"href":"https:\/\/cknotes.com\/wp-json\/wp\/v2\/posts\/248","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/cknotes.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/cknotes.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/cknotes.com\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/cknotes.com\/wp-json\/wp\/v2\/comments?post=248"}],"version-history":[{"count":0,"href":"https:\/\/cknotes.com\/wp-json\/wp\/v2\/posts\/248\/revisions"}],"wp:attachment":[{"href":"https:\/\/cknotes.com\/wp-json\/wp\/v2\/media?parent=248"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/cknotes.com\/wp-json\/wp\/v2\/categories?post=248"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/cknotes.com\/wp-json\/wp\/v2\/tags?post=248"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}