大家一起來學習一下,代碼如下:
//這裡是DLL入口
#import "C:/Windows/system32/msXML.dll"
#import "C:/Windows/system32/msXML2.dll"
using namespace MSXML2;
HRESULT ComInit();
#include "stdio.h"
int APIENTRY WinMain(HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPSTR lpCmdLine,
int nCmdShow)
{
ComInit(); //Examda提示: 調用下面初始化COM的函數
IXMLHTTPRequestPtr XMLrequest; //定義變量
xmlrequest.CreateInstance("Msxml2.XMLHTTP");
XMLrequest->open(_bstr_t("GET"),_bstr_t("http://www.baidu.com/s/index.ASP?wd=vc+Com&tn=site888_1_pg&cl=3&IE=utf-8"),_variant_t("false"));
XMLrequest->send();
BSTR bstrbody;
XMLrequest->get_responseText(&bstrbody);
_bstr_t bstrtbody(bstrbody);
MessageBox(0, (LPCTSTR)bstrtbody, "OK", MB_OK);
return 0;
}
//這裡是初始化COM
HRESULT ComInit()
{
HRESULT hr = S_OK;
if FAILED(CoInitialize(NULL))
{
CoUninitialize();
hr = E_UNEXPECTED;
}
return hr;
}