{"id":252,"date":"2014-07-23T06:47:24","date_gmt":"2014-07-23T15:47:24","guid":{"rendered":"http:\/\/blog.box.kr\/?p=252"},"modified":"2014-07-23T06:47:24","modified_gmt":"2014-07-23T15:47:24","slug":"%ea%b0%9c%eb%b0%9cvc-urlencode-urldecode-utf8-%eb%b3%80%ed%99%98-%ec%86%8c%ec%8a%a4","status":"publish","type":"post","link":"https:\/\/blog.box.kr\/?p=252","title":{"rendered":"[\uac1c\ubc1c\/VC++] URLEncode, URLDecode, UTF8 \ubcc0\ud658 \uc18c\uc2a4"},"content":{"rendered":"<div style=\"color: #333333;\">\n<div class=\"article_info\" style=\"color: #8b8b8b;\">\n<div class=\"article_info_content\">\n<h2 class=\"article_title\" style=\"color: #0b0c5e;\"><a style=\"color: #0b0c5e;\" href=\"http:\/\/sbrich.tistory.com\/833\">[\uac1c\ubc1c\/VC++] URLEncode, URLDecode, UTF8 \ubcc0\ud658 \uc18c\uc2a4<\/a><\/h2>\n<p><a style=\"color: #333333;\" href=\"http:\/\/sbrich.tistory.com\/category\/IT\/%EA%B0%9C%EB%B0%9C\">IT\/\uac1c\ubc1c<\/a>\u00a02011\/02\/10 12:05\n<\/div>\n<\/div>\n<\/div>\n<div class=\"article_post\" style=\"color: #333333;\">\n<p>[\uac1c\ubc1c\/VC++] URLEncode, URLDecode, UTF8 \ubcc0\ud658 \uc18c\uc2a4<\/p>\n<p>\uc544\ub798 \uc18c\uc2a4\ub294 \uba40\ud2f0\ubc14\uc774\ud2b8 \ubb38\uc790\uc9d1\ud569 \ud504\ub85c\uc81d\ud2b8 \uc124\uc815\uc73c\ub85c \uc791\uc5c5\ud574\uc57c \uc791\ub3d9\ub41c\ub2e4.<\/p>\n<p>inline BYTE toHex(const BYTE &amp;x)<br \/>\n{<br \/>\nreturn x &gt; 9 ? x + 55: x + 48;<br \/>\n}<\/p>\n<p>CString URLEncode(CString sIn)<br \/>\n{<br \/>\nCString sOut;<br \/>\nconst int nLen = sIn.GetLength() + 1;<br \/>\nregister LPBYTE pOutTmp = NULL;<br \/>\nLPBYTE pOutBuf = NULL;<br \/>\nregister LPBYTE pInTmp = NULL;<br \/>\nLPBYTE pInBuf =(LPBYTE)sIn.GetBuffer(nLen);<br \/>\nBYTE b = 0;<\/p>\n<p>\/\/alloc out buffer<br \/>\npOutBuf = (LPBYTE)sOut.GetBuffer(nLen*3 &#8211; 2);\/\/new BYTE [nLen * 3];<\/p>\n<p>if(pOutBuf)<br \/>\n{<br \/>\npInTmp\u00a0\u00a0 = pInBuf;<br \/>\npOutTmp = pOutBuf;<\/p>\n<p>\/\/ do encoding<br \/>\nwhile (*pInTmp)<br \/>\n{<br \/>\nif(isalnum(*pInTmp))<br \/>\n*pOutTmp++ = *pInTmp;<br \/>\n<span id=\"callbacknestsbrichtistorycom8332003\"><\/span>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 else<br \/>\nif(isspace(*pInTmp))<br \/>\n*pOutTmp++ = &#8216;+&#8217;;<br \/>\nelse<br \/>\n{<br \/>\n*pOutTmp++ = &#8216;%&#8217;;<br \/>\n*pOutTmp++ = toHex(*pInTmp&gt;&gt;4);<br \/>\n*pOutTmp++ = toHex(*pInTmp%16);<br \/>\n}<br \/>\npInTmp++;<br \/>\n}<br \/>\n*pOutTmp = &#8216;\u0000&#8217;;<br \/>\n\/\/sOut=pOutBuf;<br \/>\n\/\/delete [] pOutBuf;<br \/>\nsOut.ReleaseBuffer();<br \/>\n}<br \/>\nsIn.ReleaseBuffer();<br \/>\nreturn sOut;<br \/>\n}<br \/>\nUrlDecode\uff1a<br \/>\n#define IsHexNum(c) ((c &gt;= &#8216;0&#8217; &amp;&amp; c &lt;= &#8216;9&#8217;) || (c &gt;= &#8216;A&#8217; &amp;&amp; c &lt;= &#8216;F&#8217;) || (c &gt;= &#8216;a&#8217; &amp;&amp; c &lt;= &#8216;f&#8217;))<\/p>\n<p>CString Utf8ToStringT(LPSTR str)<br \/>\n{<br \/>\n_ASSERT(str);<br \/>\nUSES_CONVERSION;<br \/>\nWCHAR *buf;<br \/>\nint length = MultiByteToWideChar(CP_UTF8, 0, str, -1, NULL, 0);<br \/>\nbuf = new WCHAR[length+1];<br \/>\nZeroMemory(buf, (length+1) * sizeof(WCHAR));<br \/>\nMultiByteToWideChar(CP_UTF8, 0, str, -1, buf, length);<\/p>\n<p>return (CString(W2T(buf)));<br \/>\n}<\/p>\n<p>CString UrlDecode(LPCTSTR url)<br \/>\n{<br \/>\n_ASSERT(url);<br \/>\nUSES_CONVERSION;<br \/>\nLPSTR _url = T2A(const_cast&lt;LPTSTR&gt;(url));<br \/>\nint i = 0;<br \/>\nint length = (int)strlen(_url);<br \/>\nCHAR *buf = new CHAR[length];<br \/>\nZeroMemory(buf, length);<br \/>\nLPSTR p = buf;<br \/>\nwhile(i &lt; length)<br \/>\n{<br \/>\nif(i &lt;= length -3 &amp;&amp; _url[i] == &#8216;%&#8217; &amp;&amp; IsHexNum(_url[i+1]) &amp;&amp; IsHexNum(_url[i+2]))<br \/>\n{<br \/>\nsscanf(_url + i + 1, &#8220;%x&#8221;, p++);<br \/>\ni += 3;<br \/>\n}<br \/>\nelse<br \/>\n{<br \/>\n*(p++) = _url[i++];<br \/>\n}<br \/>\n}<br \/>\nreturn Utf8ToStringT(buf);<br \/>\n}<\/p>\n<\/div>\n","protected":false},"excerpt":{"rendered":"<p>[\uac1c\ubc1c\/VC++] URLEncode, URLDecode, UTF8 \ubcc0\ud658 \uc18c\uc2a4 IT\/\uac1c\ubc1c\u00a02011\/02\/10 12:05 [\uac1c\ubc1c\/VC++] URLEncode, URLDecode, UTF8 \ubcc0\ud658 \uc18c\uc2a4 \uc544\ub798 \uc18c\uc2a4\ub294 \uba40\ud2f0\ubc14\uc774\ud2b8 \ubb38\uc790\uc9d1\ud569 \ud504\ub85c\uc81d\ud2b8 \uc124\uc815\uc73c\ub85c \uc791\uc5c5\ud574\uc57c \uc791\ub3d9\ub41c\ub2e4. inline BYTE toHex(const BYTE &amp;x) { return x &gt; 9 ? x + 55: x + 48; } CString URLEncode(CString sIn) { CString sOut; const int nLen = sIn.GetLength() + 1; register LPBYTE pOutTmp = NULL; LPBYTE pOutBuf = NULL; register LPBYTE pInTmp = NULL; LPBYTE pInBuf =(LPBYTE)sIn.GetBuffer(nLen); BYTE b = 0; \/\/alloc out buffer pOutBuf = (LPBYTE)sOut.GetBuffer(nLen*3 &#8211; 2);\/\/new BYTE [nLen * 3]; if(pOutBuf) { pInTmp\u00a0\u00a0 = pInBuf; pOutTmp = pOutBuf; \/\/ do encoding while (*pInTmp) { if(isalnum(*pInTmp)) *pOutTmp++ = *pInTmp; \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 else if(isspace(*pInTmp)) *pOutTmp++ = &#8216;+&#8217;; else { *pOutTmp++ = &#8216;%&#8217;; *pOutTmp++ = toHex(*pInTmp&gt;&gt;4); *pOutTmp++ = toHex(*pInTmp%16); } pInTmp++; } *pOutTmp = &#8216;&#8217;; \/\/sOut=pOutBuf; \/\/delete [] pOutBuf; sOut.ReleaseBuffer(); } sIn.ReleaseBuffer(); return sOut; } UrlDecode\uff1a #define IsHexNum(c) ((c &gt;= &#8216;0&#8217; &amp;&amp; c &lt;= &#8216;9&#8217;) || (c &gt;= &#8216;A&#8217; &amp;&amp; c &lt;= &#8216;F&#8217;) || (c &gt;= &#8216;a&#8217; &amp;&amp; c &lt;= &#8216;f&#8217;)) CString Utf8ToStringT(LPSTR str) { _ASSERT(str); USES_CONVERSION; WCHAR *buf; int length = MultiByteToWideChar(CP_UTF8, 0, str, -1, NULL, 0); buf = new WCHAR[length+1]; ZeroMemory(buf, (length+1) * sizeof(WCHAR)); MultiByteToWideChar(CP_UTF8, 0, str, -1, buf, length); return (CString(W2T(buf))); } CString UrlDecode(LPCTSTR url) [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_mi_skip_tracking":false,"ngg_post_thumbnail":0,"spay_email":"","jetpack_publicize_message":"","jetpack_is_tweetstorm":false,"jetpack_publicize_feature_enabled":true},"categories":[9,7],"tags":[],"aioseo_notices":[],"jetpack_featured_media_url":"","jetpack_publicize_connections":[],"jetpack_sharing_enabled":true,"jetpack_shortlink":"https:\/\/wp.me\/p5q9Zn-44","jetpack-related-posts":[{"id":250,"url":"https:\/\/blog.box.kr\/?p=250","url_meta":{"origin":252,"position":0},"title":"[\uac1c\ubc1c\/VC++] URLEncode, URLDecode, \uc720\ub2c8\ucf54\ub4dc \ubcc0\ud658 \uc18c\uc2a4","date":"2014-07-23","format":false,"excerpt":"[\uac1c\ubc1c\/VC++] URLEncode, URLDecode, \uc720\ub2c8\ucf54\ub4dc \ubcc0\ud658 \uc18c\uc2a4 IT\/\uac1c\ubc1c\u00a02011\/02\/10 12:08 [\uac1c\ubc1c\/VC++] URLEncode, URLDecode, UTF8 \ubcc0\ud658 \uc18c\uc2a4 [\uc720\ub2c8\ucf54\ub4dc \ubb38\uc790\uc9d1\ud569\uc6a9] CString Unicode_URLDecode( CString strEncodedText ) { CString strResult; wchar_t ch0, ch1, ch2; wchar_t wch; TCHAR tch; int i = 0; while( i<strEncodedText.GetLength() ) { tch = strEncodedText.GetAt(i); if( tch != _T('%') ) { \/\/\u2026","rel":"","context":"In &quot;C\/C++&quot;","img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":441,"url":"https:\/\/blog.box.kr\/?p=441","url_meta":{"origin":252,"position":1},"title":"CStirng \u2194 char * (Unicode \u2194 ANSI)","date":"2014-12-15","format":false,"excerpt":"\u203b\u00a0Format \uc9c0\uc815 \uac00\ub2a5 (CString \u2192 char *) \/\/\u00a0Static CString strText = _T(\"casting test\"); char szText[128]; sprintf_s(szText, 128, \"%S\", strText); \/\/ Using\u00a0szText... \/\/ Dynamic CString strText = _T(\"casting test\"); const size_t size = strText.GetLength(); char *pszText = new char[size]; sprintf_s(pszText,\u00a0size, \"%S\", strText); \/\/ Using\u00a0pszText... \/\/ \ub625 \uce58\uc6b0\ub294 \uac70 \uc78a\uc9c0\ub9d0\uc790 delete\u00a0pszText; \u203b\u2026","rel":"","context":"In &quot;C\/C++&quot;","img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":200,"url":"https:\/\/blog.box.kr\/?p=200","url_meta":{"origin":252,"position":2},"title":"\uc774\ubc88 \ud3ec\uc2a4\ud305\uc740 \ud2b9\uc815\uc0ac\uc774\ud2b8\uc758 HTML \ud0dc\uadf8\ub97c\u2026","date":"2014-07-16","format":false,"excerpt":"\uc774\ubc88 \ud3ec\uc2a4\ud305\uc740 \ud2b9\uc815\uc0ac\uc774\ud2b8\uc758 HTML \ud0dc\uadf8\ub97c \uac00\uc838\uc640\uc11c \ucd9c\ub825\ud558\ub294 \uac83\uae4c\uc9c0 \ub2e4\ub8f9\ub2c8\ub2e4. \uac1c\ubc1c \ud234\uc740 Visual Studio 2012\ub97c \uc0ac\uc6a9\ud588\uc2b5\ub2c8\ub2e4. # \ud654\uba74 \uad6c\uc131 - url \uc601\uc5ed - url \uc774\ub3d9 \ubc84\ud2bc - html \uac00\uc838\uc624\uae30 \ubc84\ud2bc - webBrowser \uc601\uc5ed - \ub514\ubc84\uae451 \uc601\uc5ed - \ub514\ubc84\uae452 \uc601\uc5ed \uacb0\uacfc\ubb3c\ub294 \uac04\ub2e8\ud569\ub2c8\ub2e4. \ud574\ub2f9 URL\uc5d0 \uc774\ub3d9\ud558\uc5ec webBrowser\uc758 \ud6c4\ud0b9(?) \ucf5c\ubc31(?)\u00a0\uc815\ubcf4\ub97c \ucd9c\ub825(\ub514\ubc84\uae451)\ud558\uace0 scan\ubc84\ud2bc\uc744 \ud1b5\ud574 html\ub0b4\uc6a9\uc744\u2026","rel":"","context":"In &quot;C\/C++&quot;","img":{"alt_text":"","src":"http:\/\/cfile23.uf.tistory.com\/image\/236391385315B70E32D9B7","width":350,"height":200},"classes":[]},{"id":248,"url":"https:\/\/blog.box.kr\/?p=248","url_meta":{"origin":252,"position":3},"title":"[\uac1c\ubc1c\/VC++] WebBrowser Control \uc774\ubca4\ud2b8 \uc5f0\uacb0 &#8211; C++","date":"2014-07-23","format":false,"excerpt":"IT\/\uac1c\ubc1c\u00a02011\/02\/10 12:12 [\uac1c\ubc1c\/VC++] WebBrowser Control \uc774\ubca4\ud2b8 \uc5f0\uacb0 - C++ WebBrowser Control IDispatch IWebBrowser2 .ReadyState READYSTATE_COMPLETE .Navigate2() .get_Document() \/\/ IDispatch -> IHTMLDocument2 .get_StatusText() on DownloadBegin on DocumentComplete on DownloadComplete IOleObject \u00a0 IHTMLWindow2 IHTMLDocument2 .get_all() .get_parentWindow() \/\/ IHTMLWindow2 IHTMLElementCollection .item() .tags \/\/ IHTMLElementCollection IHTMLElement a connectable object IConnectionPointContainer .FindConnectionPoint() \/\/ DHTMLElementEvents2 DHTMLElementEvents2\u2026","rel":"","context":"In &quot;C\/C++&quot;","img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":216,"url":"https:\/\/blog.box.kr\/?p=216","url_meta":{"origin":252,"position":4},"title":"BSTR &#8211; char*\uac04\uc758 \ubcc0\ud658 \ubc0f BSTR\uc5d0 \ub300\ud574&#8230;","date":"2014-07-23","format":false,"excerpt":"BSTR - char*\uac04\uc758 \ubcc0\ud658 #include <afxconv.h>void BSTRtoCHAR(char *Msg[], const BSTR conv) { USES_CONVERSION; strcpy( *Msg, OLE2T(conv) ); }void CHARtoBSTR( BSTR *Msg, const char *conv ) { USES_CONVERSION; *Msg = T2OLE(conv); \/\/ *Msg = SysAllocString( A2W(conv) ); } \u00a0strText=SysAllocStringLen(szOleChar,iLen); \u00a0 \/\/ BSTR\uc5d0 \uacf5\uac04 \ud560\ub2f9.. printf(\"SysStringLen(strText) = %un\",SysStringLen(strText)); \u00a0 \u00a0\/\/ BSTR String\uc758\u2026","rel":"","context":"In &quot;C\/C++&quot;","img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":597,"url":"https:\/\/blog.box.kr\/?p=597","url_meta":{"origin":252,"position":5},"title":"[\ud38c][AngularJS] \ubc30\uc6b0\ub294 \ubc29\ubc95 &amp; \uae30\ubcf8 \uac1c\ub150 \uc7a1\uae30","date":"2015-02-02","format":false,"excerpt":"http:\/\/mobicon.tistory.com\/281 AngularJS\/Concept AngularJS\ub97c \ubc30\uc6b0\uae30 \uc704\ud574\u00a0\uc88c\ucda9\uc6b0\ub3cc \ud558\uba70 \uc77d\uace0, \ubcf4\uace0,\u00a0\ub4e3\uace0, \ucf54\ub529\ud574\ubcf8 \ucf54\uc2a4\ub97c \ub098\ub984 \uc815\ub9ac\ud574 \ubcf4\uc558\ub2e4. 1.\u00a0\uac1c\ub150\uc7a1\uae30 -\u00a0Angular's father\uc778\u00a0\ubbf8\uc2a4\ucf54\ub2d8\uc758\u00a0AngularJS \uc18c\uac1c \ub3d9\uc601\uc0c1\uc744 \ubcf8\ub2e4 : \ub2e8\uacc4\ubcc4\ub85c jQuery\uc640 \uc798 \ube44\uad50\ud558\uace0 \uc788\ub2e4 \u00a0 - Art of AngularJS\ub97c \ubcf4\uace0\uc11c \uc774\uc81c \ubc30\uc6cc\uc57c\ud560 \ud544\uc694\uc131\uc744 \ub290\uaef4\ubcf4\uc138\uc694. \uc774\uc81c \uc2dc\uc791\ud558\uc138\uc694. \u00a0 \u00a0\u00a0The Art of AngularJS from Matt Raible - AngularJS\uc758 \uc911\uc694 \uc694\uc18c\uc640 \uae30\ubcf8\uae30\ub97c\u2026","rel":"","context":"In &quot;JAVA&quot;","img":{"alt_text":"","src":"http:\/\/cfile29.uf.tistory.com\/image\/2161163B517694CB2CA7B5","width":350,"height":200},"classes":[]}],"_links":{"self":[{"href":"https:\/\/blog.box.kr\/index.php?rest_route=\/wp\/v2\/posts\/252"}],"collection":[{"href":"https:\/\/blog.box.kr\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.box.kr\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.box.kr\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.box.kr\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=252"}],"version-history":[{"count":0,"href":"https:\/\/blog.box.kr\/index.php?rest_route=\/wp\/v2\/posts\/252\/revisions"}],"wp:attachment":[{"href":"https:\/\/blog.box.kr\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=252"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.box.kr\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=252"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.box.kr\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=252"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}