C++ visualc&x2B+;2013调试断言失败=运行时atlcomcli.h中的0
我正在尝试创建IXMLHTTPREQUEST的智能指针,并让它打开到示例URL的http连接。添加了一些打印行以查找其失败之处C++ visualc&x2B+;2013调试断言失败=运行时atlcomcli.h中的0,c++,pointers,com,assertion,C++,Pointers,Com,Assertion,我正在尝试创建IXMLHTTPREQUEST的智能指针,并让它打开到示例URL的http连接。添加了一些打印行以查找其失败之处 static const TCHAR* const g_lpszSOAPEndpointURL = _T("http://www.webservicex.net/country.asmx?op=GetCurrencyByCountry"); USES_CONVERSION; printf("Hello 2 \n"); C
static const TCHAR* const g_lpszSOAPEndpointURL =
_T("http://www.webservicex.net/country.asmx?op=GetCurrencyByCountry");
USES_CONVERSION;
printf("Hello 2 \n");
CComPtr<IXMLHTTPRequest> spXMLHTTP = NULL;
printf("Hello 3A...\n");
HRESULT hr = spXMLHTTP.CoCreateInstance(__uuidof(IXMLHttpRequest));
if (S_OK != hr)
printf("Hello 3...\n");
else
printf("Pointer creation failed..");
// Initialize the Synchronous HTTP POST request
spXMLHTTP->open(BSTR("POST"), BSTR(g_lpszSOAPEndpointURL),
_variant_t(VARIANT_FALSE), _variant_t(""), _variant_t(""));
printf("Hello 4...\n");
printf("Hello 5...\n");
static const TCHAR*const g_lpszSOAPEndpointURL=
_T(“http://www.webservicex.net/country.asmx?op=GetCurrencyByCountry");
使用_转换;
printf(“Hello 2\n”);
CComPtr spXMLHTTP=NULL;
printf(“你好3A…\n”);
HRESULT hr=spXMLHTTP.CoCreateInstance(uu uuidof(IXMLHttpRequest));
如果(S_OK!=小时)
printf(“你好3…\n”);
其他的
printf(“指针创建失败…”);
//初始化同步HTTP POST请求
spXMLHTTP->open(BSTR(“POST”)、BSTR(g_lpszSOAPEndpointURL),
_变量t(变量t为假)、变量t(“”)、变量t(“”);
printf(“你好4…\n”);
printf(“你好5…\n”);
输出在“
Hello 3…
”之后停止,并抛出atlcomcli
运行时错误。最后两个参数应该是变量中包含的BSTR
。但是,它们也是可选的。尝试使用\u variant\t(BSTR(L“”)
,或\u variant\t()
检查空变量?错误检查非常不充分,printf()不足以阻止程序失败。由于spXMLHTTP为NULL,因此获得断言。创建COM对象的实例需要CLSID,而不是IID。例如,使用spXMLHTTP.CoCreateInstance(L“Msxml2.XMLHTTP.6.0”);也不要忽略open()的返回值。谢谢!我通过放入clsid修复了实例问题。我成功地打开了连接。PS-我是COM编程新手。