VC中使用IXMLHTTPRequest获取URL信息的问题,有代码*********************************************
#import "msxml4.dll"
using namespace MSXML2;
void XMLHttpRequestSample()
{
IXMLHTTPRequestPtr pIXMLHTTPRequest = NULL;
BSTR bstrString = NULL;
HRESULT hr;
try {
hr=pIXMLHTTPRequest.CreateInstance("Msxml2.XMLHTTP.4.0");
SUCCEEDED(hr) ? 0 : throw hr;
hr=pIXMLHTTPRequest->open("GET", "http://XMLSampleServer/CatalogServer.asp", false);
SUCCEEDED(hr) ? 0 : throw hr;
hr=pIXMLHTTPRequest->send();
SUCCEEDED(hr) ? 0 : throw hr;
bstrString=pIXMLHTTPRequest->responseText;
MessageBox(NULL, _bstr_t(bstrString), _T("Results"), MB_OK);
if(bstrString)
{
::SysFreeString(bstrString);
bstrString = NULL;
}
} catch (...) {
MessageBox(NULL, _T("Exception occurred"), _T("Error"), MB_OK);
if(bstrString)
::SysFreeString(bstrString);
}
}
上面的代码,不能成功执行,在CreateInstance(...)退出,为什么?