Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. XML / XSL
  4. Failed to CreateInstance while using IXMLHttpRequestPtr

Failed to CreateInstance while using IXMLHttpRequestPtr

Scheduled Pinned Locked Moved XML / XSL
helpcomquestion
4 Posts 3 Posters 14 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • A Offline
    A Offline
    adapterJohn
    wrote on last edited by
    #1

    Hello, I am using MSXML to get HTTP response from a webserver. The problem is when I use pIXMLHTTPRequest.CreateInstance("Microsoft.XMLHTTP"); it always goes to error and can't continue to open the connection. Can someone tell me where possibly the problem is, and why should I create the instance? Many thanks in advance. ***************************************** BOOL CAPIDlg::MakeRequest() { BOOL bRetVal=FALSE; BSTR Result=NULL; try{ MSXML::IXMLHttpRequestPtr pIXMLHTTPRequest; HRESULT hResult; hResult = pIXMLHTTPRequest.CreateInstance("Microsoft.XMLHTTP"); //Test the connection if ( FAILED(hResult) ) { MessageBox("Fail to create the connection"); return bRetVal; } MessageBox("Continue anyway"); //Open the connection pIXMLHTTPRequest->open("POST",(_bstr_t)"www.yahoo.com"); //Send the request pIXMLHTTPRequest->send(); MessageBox("Success to open"); //Get the result Result=pIXMLHTTPRequest->responseText; if(Result) //Display the result {m_Result.SetWindowText((_bstr_t)Result); } else //Report error MessageBox("Can't make the connection"); } catch(...) { //Report error MessageBox("Can't initialize the HTTP request"); } return true; }

    M 1 Reply Last reply
    0
    • A adapterJohn

      Hello, I am using MSXML to get HTTP response from a webserver. The problem is when I use pIXMLHTTPRequest.CreateInstance("Microsoft.XMLHTTP"); it always goes to error and can't continue to open the connection. Can someone tell me where possibly the problem is, and why should I create the instance? Many thanks in advance. ***************************************** BOOL CAPIDlg::MakeRequest() { BOOL bRetVal=FALSE; BSTR Result=NULL; try{ MSXML::IXMLHttpRequestPtr pIXMLHTTPRequest; HRESULT hResult; hResult = pIXMLHTTPRequest.CreateInstance("Microsoft.XMLHTTP"); //Test the connection if ( FAILED(hResult) ) { MessageBox("Fail to create the connection"); return bRetVal; } MessageBox("Continue anyway"); //Open the connection pIXMLHTTPRequest->open("POST",(_bstr_t)"www.yahoo.com"); //Send the request pIXMLHTTPRequest->send(); MessageBox("Success to open"); //Get the result Result=pIXMLHTTPRequest->responseText; if(Result) //Display the result {m_Result.SetWindowText((_bstr_t)Result); } else //Report error MessageBox("Can't make the connection"); } catch(...) { //Report error MessageBox("Can't initialize the HTTP request"); } return true; }

      M Offline
      M Offline
      Michael A Barnhart
      wrote on last edited by
      #2

      Are you calling CoInitialize? Ref: Applications must initialize the COM library before they can call COM library functions. From the MSDN library. HRESULT hr = CoInitialize(NULL); bool bRetVal; bRetVal=false; IXMLHttpRequestPtr pIXMLHTTPRequest; HRESULT hResult; hResult = pIXMLHTTPRequest.CreateInstance("Microsoft.XMLHTTP"); //Test the connection if ( FAILED(hResult) ) { MessageBox("Fail to create the connection"); return bRetVal; } Workes fine for in a simple dialog initialization test. "I will find a new sig someday."

      A 1 Reply Last reply
      0
      • M Michael A Barnhart

        Are you calling CoInitialize? Ref: Applications must initialize the COM library before they can call COM library functions. From the MSDN library. HRESULT hr = CoInitialize(NULL); bool bRetVal; bRetVal=false; IXMLHttpRequestPtr pIXMLHTTPRequest; HRESULT hResult; hResult = pIXMLHTTPRequest.CreateInstance("Microsoft.XMLHTTP"); //Test the connection if ( FAILED(hResult) ) { MessageBox("Fail to create the connection"); return bRetVal; } Workes fine for in a simple dialog initialization test. "I will find a new sig someday."

        A Offline
        A Offline
        adapterJohn
        wrote on last edited by
        #3

        Thanks a lot, it helps!

        P 1 Reply Last reply
        0
        • A adapterJohn

          Thanks a lot, it helps!

          P Offline
          P Offline
          pix_programmer
          wrote on last edited by
          #4

          Hi! Will this code work with Managed C++/CLI also? What else need to be done to make this code work with Managed C++?

          int _tmain(int argc, _TCHAR* argv[])
          {
          std::ostringstream XmlLogrequest;
          XmlLogrequest << "<?xml version="
          << "\""
          << "1.0"
          << "\""
          << "?>"
          << "<request action = "
          << "\"registration"
          << "\""
          << ">"
          << "<element id="
          << "\"id001" << "\""
          << ">"

          //cout << XmlLogrequest.str();
          IXMLHTTPRequestPtr pIXMLHTTPRequest = NULL;
          BSTR bstrString = NULL;
          HRESULT hr = CoInitialize(NULL);
          string test = XmlLogrequest.str().substr(0,XmlLogrequest.str().size());
          cout << test<<"\n";
          try {
          hr=pIXMLHTTPRequest.CreateInstance("Msxml2.XMLHTTP.3.0");
          //SUCCEEDED(hr) ? 0 : throw hr;

          	pIXMLHTTPRequest->open("POST", "https://live.jqk365.com/cgibin/EClientIntegration",false);
          //	SUCCEEDED(hr) ? 0 : throw hr;
          	
          	hr=pIXMLHTTPRequest->send(test.c\_str());
          	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("Error"), \_T("Error"), MB\_OK);
          	if(bstrString)
          		::SysFreeString(bstrString);
          }
          
          
          return 0;
          

          }

          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups