{"id":228,"date":"2014-07-23T05:40:38","date_gmt":"2014-07-23T14:40:38","guid":{"rendered":"http:\/\/blog.box.kr\/?p=228"},"modified":"2014-07-23T05:40:38","modified_gmt":"2014-07-23T14:40:38","slug":"mfc-c%eb%a1%9c-%ed%8a%b9%ec%a0%95-%ec%82%ac%ec%9d%b4%ed%8a%b8-%ea%b0%80%ec%a0%b8%ec%99%80%ec%84%9c-%eb%b6%84%ec%84%9d-%ed%95%98%ea%b8%b0-%ec%86%8c%ec%8a%a4","status":"publish","type":"post","link":"https:\/\/blog.box.kr\/?p=228","title":{"rendered":"MFC \/ C++\ub85c \ud2b9\uc815 \uc0ac\uc774\ud2b8 \uac00\uc838\uc640\uc11c \ubd84\uc11d \ud558\uae30 \uc18c\uc2a4"},"content":{"rendered":"<pre style=\"color: #000000;\"><code><dfn style=\"color: #500070;\">#include &lt;stdio.h&gt;<\/dfn>\n<dfn style=\"color: #500070;\">#include &lt;windows.h&gt;<\/dfn>\n<dfn style=\"color: #500070;\">#include &lt;wininet.h&gt;<\/dfn>\n<dfn style=\"color: #500070;\">#include &lt;string&gt;<\/dfn>\n<dfn style=\"color: #500070;\">#include &lt;comdef.h&gt;<\/dfn>\n<dfn style=\"color: #500070;\">#include &lt;mshtml.h&gt; <\/dfn>\n\n<dfn style=\"color: #500070;\">#import &lt;mshtml.tlb&gt; no_auto_exclude <\/dfn>\n\n<dfn style=\"color: #500070;\">#pragma comment(lib, \"wininet.lib\")<\/dfn>\n\n<dfn style=\"color: #500070;\">#include &lt;iostream&gt;<\/dfn>\n<dfn style=\"color: #500070;\">#include &lt;fstream&gt;<\/dfn>\n\n<var style=\"color: #0000b0;\">using<\/var> <var style=\"color: #0000b0;\">namespace<\/var> std;\n\n<var style=\"color: #0000b0;\">int<\/var> main(<var style=\"color: #0000b0;\">int<\/var> argc, <var style=\"color: #0000b0;\">char<\/var>* argv[]){\n\tCoInitialize(NULL);\n\n\tofstream dbfile (<kbd style=\"color: #600030;\">\"output.db\"<\/kbd>);\n\tstring sLI;\n\tstring m_strURL;\n\tHINTERNET hOpen, hFile;\n\n\tMSHTML::IHTMLDocument2Ptr pDoc;\n\tHRESULT hr = CoCreateInstance(CLSID_HTMLDocument, NULL, CLSCTX_INPROC_SERVER, IID_IHTMLDocument2, (<var style=\"color: #0000b0;\">void<\/var>**)&amp;pDoc);\n\n\tSAFEARRAY* psa = SafeArrayCreateVector(VT_VARIANT, 0, 1);\n\tVARIANT *param;\n\n\thOpen = InternetOpen(<kbd style=\"color: #600030;\">\"UN\/1.0\"<\/kbd>, INTERNET_OPEN_TYPE_PRECONFIG, NULL, NULL, 0);\n\n\thFile = InternetOpenUrl(hOpen, <kbd style=\"color: #600030;\">\"<a style=\"color: #000070;\" href=\"http:\/\/online.wsj.com\/public\/page\/news-global-world.html\">http:\/\/online.wsj.com\/public\/page\/news-global-world.html\"<\/a><\/kbd>, NULL, 0, 0, 0);\n\n\t<var style=\"color: #0000b0;\">if<\/var>(hFile){\n\t\tCHAR buffer[10*1024];\n\t\tDWORD dwRead;\n\n\t\t<var style=\"color: #0000b0;\">while<\/var>(InternetReadFile(hFile, buffer, 1024, &amp;dwRead)){\n\t\t\t<var style=\"color: #0000b0;\">if<\/var>(dwRead == 0)\n\t\t\t\t<var style=\"color: #0000b0;\">break<\/var>;\n\n\t\t\tbuffer[dwRead] = 0;\n\n\t\t\tbstr_t bsData = (LPCTSTR)buffer;\n\t\t\thr =  SafeArrayAccessData(psa, (LPVOID*)&amp;param);\n\t\t\tparam-&gt;vt = VT_BSTR;\n\t\t\tparam-&gt;bstrVal = (BSTR)bsData;\n\n\t\t\tcout &lt;&lt; buffer &lt;&lt; endl;\n\t\t\tdbfile &lt;&lt; buffer &lt;&lt; endl;\n\n\t\t\thr = pDoc-&gt;write(psa);\n\n\t\t} <cite style=\"color: #007000;\">\/\/end while loop<\/cite>\n\n\t\thr = pDoc-&gt;close();\n\t\tInternetCloseHandle(hFile);\n\t\tSafeArrayDestroy(psa);\n\t}\n\n\tInternetCloseHandle(hOpen);\n\tdbfile.close();\n\n\tCoUninitialize();\n\t<var style=\"color: #0000b0;\">return<\/var> 1;\n}<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>#include &lt;stdio.h&gt; #include &lt;windows.h&gt; #include &lt;wininet.h&gt; #include &lt;string&gt; #include &lt;comdef.h&gt; #include &lt;mshtml.h&gt; #import &lt;mshtml.tlb&gt; no_auto_exclude #pragma comment(lib, &#8220;wininet.lib&#8221;) #include &lt;iostream&gt; #include &lt;fstream&gt; using namespace std; int main(int argc, char* argv[]){ CoInitialize(NULL); ofstream dbfile (&#8220;output.db&#8221;); string sLI; string m_strURL; HINTERNET hOpen, hFile; MSHTML::IHTMLDocument2Ptr pDoc; HRESULT hr = CoCreateInstance(CLSID_HTMLDocument, NULL, CLSCTX_INPROC_SERVER, IID_IHTMLDocument2, (void**)&amp;pDoc); SAFEARRAY* psa = SafeArrayCreateVector(VT_VARIANT, 0, 1); VARIANT *param; hOpen = InternetOpen(&#8220;UN\/1.0&#8221;, INTERNET_OPEN_TYPE_PRECONFIG, NULL, NULL, 0); hFile = InternetOpenUrl(hOpen, &#8220;http:\/\/online.wsj.com\/public\/page\/news-global-world.html&#8221;, NULL, 0, 0, 0); if(hFile){ CHAR buffer[10*1024]; DWORD dwRead; while(InternetReadFile(hFile, buffer, 1024, &amp;dwRead)){ if(dwRead == 0) break; buffer[dwRead] = 0; bstr_t bsData = (LPCTSTR)buffer; hr = SafeArrayAccessData(psa, (LPVOID*)&amp;param); param-&gt;vt = VT_BSTR; param-&gt;bstrVal = (BSTR)bsData; cout &lt;&lt; buffer &lt;&lt; endl; dbfile &lt;&lt; buffer &lt;&lt; endl; hr = pDoc-&gt;write(psa); } \/\/end while loop hr = pDoc-&gt;close(); InternetCloseHandle(hFile); SafeArrayDestroy(psa); } InternetCloseHandle(hOpen); dbfile.close(); CoUninitialize(); return 1; }<\/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,19,7],"tags":[],"aioseo_notices":[],"jetpack_featured_media_url":"","jetpack_publicize_connections":[],"jetpack_sharing_enabled":true,"jetpack_shortlink":"https:\/\/wp.me\/p5q9Zn-3G","jetpack-related-posts":[{"id":220,"url":"https:\/\/blog.box.kr\/?p=220","url_meta":{"origin":228,"position":0},"title":"VARIANT to std::string","date":"2014-07-23","format":false,"excerpt":"Here's one way, not necessarily the best. In general, std::string doesn't play very well with VARIANT. #include <comutil.h> #include <string> std::string from_variant(VARIANT& vt) { _bstr_t bs(vt); return std::string(static_cast<const char*>(bs)); } void to_variant(const std::string& str, VARIANT& vt) { _bstr_t bs(str.c_str()); reinterpret_cast<_variant_t&>(vt) = bs; } \u00a0 \ub610\ud55c.. VARIANT\uac00 \ube44\uc5b4 \uc788\ub294\uc9c0 \ud655\uc778 \ud558\ub294\u2026","rel":"","context":"In &quot;C\/C++&quot;","img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":230,"url":"https:\/\/blog.box.kr\/?p=230","url_meta":{"origin":228,"position":1},"title":"std::string \ub2e4\ub8e8\uae30.. ( \ucc3e\uae30, \uacf5\ubc31\uc81c\uac70 \ub4f1\ub4f1)","date":"2014-07-23","format":false,"excerpt":"\ubb38\uc790\uc5f4 string #include \"StdAfx.h\" #include \"StringTest.h\" #include <algorithm> \/\/transform \uc0ac\uc6a9 #include <functional> \/\/bind1st using std::string; \/\/ \uc774\ub807\uac8c \uc9c0\uc815\ud574\uc900\ub2e4. StringTest::StringTest() { log(\"StringTest \uc0dd\uc131\uc790 \ud638\ucd9c\"); } StringTest::~StringTest(void) { log(\"StringTest \uc18c\uba78\uc790 \ud638\ucd9c\"); } void StringTest::test() { log(\"============ string class ==========\"); \/\/ \uc0dd\uc131\uc790 \u00a0 std::string s0; \/\/ \ube44\uc5b4\uc788\ub294 string std::string s1(\"012345\",3); \/\/ \uacb0\uacfc: 012\u2026","rel":"","context":"In &quot;C\/C++&quot;","img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":309,"url":"https:\/\/blog.box.kr\/?p=309","url_meta":{"origin":228,"position":2},"title":"[MFC] &#8211; \uba54\ubaa8\ub9ac \uad00\ub828 \uc815\ubcf4 \ud68d\ub4dd","date":"2014-08-09","format":false,"excerpt":"GlobalMemoryStatus()\ud568\uc218\u00a0MSDN\u00a0\ucc38\uace0\u00a0\uc608\uc81c #include\u00a0<windows.h> #define\u00a0DIV\u00a01024 char\u00a0*divisor\u00a0=\u00a0\"K\"; void main(int\u00a0argc,\u00a0char\u00a0*argv[]) { MEMORYSTATUS\u00a0stat; GlobalMemoryStatus\u00a0(&stat); printf\u00a0(\"The\u00a0MEMORYSTATUS\u00a0structure\u00a0is\u00a0%ld\u00a0bytes\u00a0long.n\", \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0stat.dwLength); printf\u00a0(\"It\u00a0should\u00a0be\u00a0%d.n\",\u00a0sizeof\u00a0(stat)); printf\u00a0(\"There\u00a0is\u00a0%ld\u00a0percent\u00a0of\u00a0memory\u00a0in\u00a0use.n\", stat.dwMemoryLoad); printf\u00a0(\"There\u00a0are\u00a0%ld\u00a0total\u00a0%sbytes\u00a0of\u00a0physical\u00a0memory.n\", stat.dwTotalPhys\/DIV,\u00a0divisor); printf\u00a0(\"There\u00a0are\u00a0%ld\u00a0free\u00a0%sbytes\u00a0of\u00a0physical\u00a0memory.n\", stat.dwAvailPhys\/DIV,\u00a0divisor); printf\u00a0(\"There\u00a0are\u00a0%ld\u00a0total\u00a0%sbytes\u00a0of\u00a0paging\u00a0file.n\", stat.dwTotalPageFile\/DIV,\u00a0divisor); printf\u00a0(\"There\u00a0are\u00a0%ld\u00a0free\u00a0%sbytes\u00a0of\u00a0paging\u00a0file.n\", stat.dwAvailPageFile\/DIV,\u00a0divisor); printf\u00a0(\"There\u00a0are\u00a0%ld\u00a0total\u00a0%sbytes\u00a0of\u00a0virtual\u00a0memory.n\", stat.dwTotalVirtual\/DIV,\u00a0divisor); printf\u00a0(\"There\u00a0are\u00a0%ld\u00a0free\u00a0%sbytes\u00a0of\u00a0virtual\u00a0memory.n\", stat.dwAvailVirtual\/DIV,\u00a0divisor); }","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":228,"position":3},"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":267,"url":"https:\/\/blog.box.kr\/?p=267","url_meta":{"origin":228,"position":4},"title":"[MFC] CListCtrl \uc120\ud0dd\ub41c \ud56d\ubaa9 Index","date":"2014-07-26","format":false,"excerpt":"\/\/ \ub2e4\uc911 \uc120\ud0dd\uc2dc void GetIndex() { int nItemCount = m_ctrlList.GetSelectedCount(); POSITION pos = m_ctrlList.GetFirstSelectedItemPosition(); for (int i = 0; i < nItemCount; i++) { int nIndex = m_ctrlList.GetNextSelectedItem(pos); } } \u00a0\/\/ \ub2e8\uc77c \uc120\ud0dd int GetIndex() { int nSelectedItem = m_ctrlList.GetNextItem( -1, LVNI_SELECTED ); CString strKey = m_ctrlList.GetItemText(nSelectedItem, 0); \u00a0\u00a0\u00a0 if\u2026","rel":"","context":"In &quot;C\/C++&quot;","img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":178,"url":"https:\/\/blog.box.kr\/?p=178","url_meta":{"origin":228,"position":5},"title":"std::map example","date":"2014-07-09","format":false,"excerpt":"\/\/ std::map example \/\/ opposite words #include <iostream> #include <map> #include <string> using namespace std; typedef std::map<std::string, std::string> TStrStrMap; typedef std::pair<std::string, std::string> TStrStrPair; int main(int argc, char *argv[]) { TStrStrMap tMap; tMap.insert(TStrStrPair(\"yes\", \"no\")); tMap.insert(TStrStrPair(\"up\", \"down\")); tMap.insert(TStrStrPair(\"left\", \"right\")); tMap.insert(TStrStrPair(\"good\", \"bad\")); std::string s; std::cout << \"Enter word: \" << std::endl;; std::cin >>\u2026","rel":"","context":"In &quot;C\/C++&quot;","img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]}],"_links":{"self":[{"href":"https:\/\/blog.box.kr\/index.php?rest_route=\/wp\/v2\/posts\/228"}],"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=228"}],"version-history":[{"count":0,"href":"https:\/\/blog.box.kr\/index.php?rest_route=\/wp\/v2\/posts\/228\/revisions"}],"wp:attachment":[{"href":"https:\/\/blog.box.kr\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=228"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.box.kr\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=228"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.box.kr\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=228"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}