visual c++ - C++ Need help converting string to tchar, tried some things from other posts, but not working -
this first c++ program have written, no means c++ programmer, please kind. needed able connect database, link , download file link. works except have hardcode link rather use link have saved in string. need convert string tchar , have tried few things, it's not working. need tchar url[] have value in string dotnetlink, instead of hard coded url in there. thank help.
string dotnetlink; //request url download send(socket,"post /getdotnetlink.php / http/1.1\r\nhost: www.domain.com\r\nconnection: close\r\n\r\n", strlen("post /getdotnetlink.php / http/1.1\r\nhost: www.domain.com\r\nconnection: close\r\n\r\n"),0); char buffer[10000]; int ndatalength; while ((ndatalength = recv(socket,buffer,10000,0)) > 0){ int = 0; while (buffer[i] >= 32 || buffer[i] == '\n' || buffer[i] == '\r') { //link download stored in string dotnetlink = dotnetlink + (buffer[i]); += 1; } } closesocket(socket); wsacleanup(); cout << dotnetlink; const tchar url[] = _t("http://www.linktomydownload.com/file.exe");
tchar typedef either char or wchar, depending on whether unicode macro defined. means if unicode not defined no conversion needed. if defined, can use multibytetowidechar function perform conversion.
as tip, tchar , related "t"-prefixed macros , typedefs things windows 95 days, when unicode support wasn't broad. nowadays should use unicode, except places require byte strings (such http protocol).
here example of how might it:
wchar szdotnetlink[256]; int length = ::multibytetowidechar(cp_utf8, 0, dotnetlink.c_str(), -1, szdotnetlink, 256); if (length == 0) // conversion failed
Comments
Post a Comment