com组件 智能指针崩溃问题崩溃问题

时间:2021-04-12 07:33:23

int main()
{
 CoInitialize(NULL);
 HRESULT hr;
 IWinHttpRequestPtr pHttpReq=NULL;
 pHttpReq.CreateInstance(__uuidof(WinHttpRequest));
 CoUninitialize();

}

上面的代码在win32工程中会崩溃的。

解决办法1:

int main()
{

CoInitialize(NULL);

{
  HRESULT hr;
  IWinHttpRequestPtr pHttpReq=NULL;
  pHttpReq.CreateInstance(__uuidof(WinHttpRequest));

}
 CoUninitialize();

return 0;

解决办法2:

int main()
{
 CoInitialize(NULL);
 HRESULT hr;
 IWinHttpRequestPtr pHttpReq=NULL;
 pHttpReq.CreateInstance(__uuidof(WinHttpRequest));
 pHttpReq=NULL;
 CoUninitialize();

return 0;

}