none
CoCreateInstance error -2147221164 on Windows Server 2008 RRS feed

  • Question

  • Greetings.

    We have some old code in our system and I'm trying to get it to work on a newer platform.  We have a C++ 6.0 dll that we call from an old MicroFocus COBOL application.  The C++ dll serves as a wrapper to call a .NET web service since we can't call it directly from COBOL.  It has been running without any problems on Windows XP, but on Windows Server 2008, I get an error code -2147221164 on the call to CoCreateInstance.  I understand this error indicates that the dll is not registered.  I never had to register it on the XP machines.

    This is the actual code being executed that is throwing the error:

     CComPtr<IServerXMLHTTPRequest>spServerXMLHTTP1;
     HRESULT hr = spServerXMLHTTP1.CoCreateInstance(CLSID_ServerXMLHTTP40);
     if (hr < 0)
     {
      ierror = sprintf(errmsg,"Critical Error CoCreateInstance %+8d",hr);
      throw (errmsg);
     }

    Here is the code for the entire function:

    //------------------------------------------------------------------------------
    //  Function uses ServerXMLHTTP to send a GET/POST/SOAP request to a .NET Web Services,
    //  and then uses MSXML DOM to process the response XML text.
    // 
    //  Illustrates calling a .NET Web Service either by sending a GET request,
    //  or a HTTP POST or by using the SOAP method.
    //
    //  iMethod parameter:
    //    0 : (Default) HTTP GET
    //    1 : HTTP POST
    //    2 : SOAP
    //------------------------------------------------------------------------------
    //_bstr_t CallWebService(LPCTSTR szSOAPRequest, LPCTSTR szSOAPAction, LPCTSTR szSOAPEndPoint)
    //_bstr_t CallWebService(TCHAR * szSOAPRequest, TCHAR * szSOAPAction, TCHAR * szSOAPEndPoint)
    _bstr_t CallWebService(TCHAR * szSOAPRequest, TCHAR * szSOAPAction, TCHAR * szSOAPEndPoint, int iMethod)
    {
      try
      {
    	char errmsg [100] = {0};
    	int ierror;
    	_bstr_t bstrRequest;
    	bstrRequest = ConvertStringToBSTR(szSOAPRequest);
    //iMethod = 0 uses HTTP GET
    //	int iMethod=0;
    //iMethod = 2 uses SOAP.
    //	int iMethod=2;
    	LPCTSTR szZipCode="";
    	USES_CONVERSION;
      //  Create an instance of ServerXMLHTTP Class
    	CComPtr<IServerXMLHTTPRequest>spServerXMLHTTP1;
    	HRESULT hr = spServerXMLHTTP1.CoCreateInstance(CLSID_ServerXMLHTTP40);
    	if (hr < 0)
    	{
    		ierror = sprintf(errmsg,"Critical Error CoCreateInstance %+8d",hr);
    		throw (errmsg);
    	}
    	TCHAR szGetURL[MAX_PATH*2]={0};
    	TCHAR szPostValue[MAX_PATH*2]={0};
    	TCHAR szSOAPReq[MAX_PATH*2]={0};
    	int iPostDataLen =0;
    	TCHAR szDataLen[10]={0};
    	switch(iMethod)
    	{
    	case 0:  //  HTTP GET
    		sprintf(szGetURL, szSOAPRequest);
        //  Initialize the Synchronous HTTP GET request
    		hr = spServerXMLHTTP1->open(_bstr_t(_T("GET")), szGetURL, VARIANT_FALSE);
    		if (hr < 0)
    		{
    			ierror = sprintf(errmsg,"Critical Error spServerXMLHTTP1->open %+8d",hr);
    			throw (errmsg);
    		}
        //  Send the HTTP GET request
    		hr = spServerXMLHTTP1->send();
    		if (hr < 0)
    		{
    			ierror = sprintf(errmsg,"Critical Error spServerXMLHTTP1->send %+8d",hr);
    			throw (errmsg);
    		}
    		break;
    	case 1:  //  HTTP POST
    		_tcscpy(szPostValue, _T("connectionid="));
    		_tcscat(szPostValue, szZipCode);
    		iPostDataLen = _tcslen(szPostValue);
    		itoa(iPostDataLen, szDataLen, 10);
        //  Initialize the Synchronous HTTP GET request
    		hr = spServerXMLHTTP1->open(_bstr_t(_T("POST")), g_lpszPostURL, VARIANT_FALSE);
    		if (hr < 0)
    		{
    			ierror = sprintf(errmsg,"Critical Error spServerXMLHTTP1->open %+8d",hr);
    			throw (errmsg);
    		}
    		spServerXMLHTTP1->setRequestHeader(_T("Content-Type"), 
    		_T("application/x-www-form-urlencoded"));
    		spServerXMLHTTP1->setRequestHeader(_T("Content-Length"), szDataLen);
        
        //  Send the HTTP POST request, along with the SOAP request envelope text
    		hr = spServerXMLHTTP1->send(szPostValue);
    		if (hr < 0)
    		{
    			ierror = sprintf(errmsg,"Critical Error spServerXMLHTTP1->send %+8d",hr);
    			throw (errmsg);
    		}
    		break;
    	case 2:  //  SOAP
        //sprintf(szSOAPReq, g_lpszSOAPReq, szZipCode);
    		hr = spServerXMLHTTP1->open(_bstr_t(_T("POST")), szSOAPEndPoint, VARIANT_FALSE);
    		if (hr < 0)
    		{
    			ierror = sprintf(errmsg,"Critical Error spServerXMLHTTP1->open %+8d",hr);
    			throw (errmsg);
    		}
        //  Set the required SOAPAction and Content-Type headers
    		hr = spServerXMLHTTP1->setRequestHeader(_T("SOAPAction"), szSOAPAction);
    		if (hr < 0)
    		{
    			ierror = sprintf(errmsg,"Critical Error spServerXMLHTTP1->setRequestHeader 1 %+8d",hr);
    			throw (errmsg);
    		}
    		hr = spServerXMLHTTP1->setRequestHeader(_bstr_t(_T("Content-Type")), 
    		_bstr_t(_T("text/xml")));
    		if (hr < 0)
    		{
    			ierror = sprintf(errmsg,"Critical Error spServerXMLHTTP1->setRequestHeader 2 %+8d",hr);
    			throw (errmsg);
    		}
        //  Send the POST request, along with the SOAP request envelope text
    		MSXML2::_SERVERXMLHTTP_OPTION srvval = SXH_OPTION_IGNORE_SERVER_SSL_CERT_ERROR_FLAGS;
    //		MSXML2::_SXH_SERVER_CERT_OPTION valopt = SXH_SERVER_CERT_IGNORE_ALL_SERVER_ERRORS;
    		_variant_t srvopt = spServerXMLHTTP1->getOption(srvval);
    //		MSXML2::_SXH_SERVER_CERT_OPTION srvopt = SXH_SERVER_CERT_IGNORE_ALL_SERVER_ERRORS;
    		spServerXMLHTTP1->setOption(srvval, srvopt);
    		hr = spServerXMLHTTP1->send (bstrRequest);
    		if (hr < 0)
    		{
    			ierror = sprintf(errmsg,"Critical Error spServerXMLHTTP1->send %+8d",hr);
    			throw (errmsg);
    		}
    		break;
    	}
      
    	if(200 == spServerXMLHTTP1->status) //Success
    	{
        //  using MSXML DOM to process the response XML text
    		CComQIPtr <IXMLDOMDocument2> spResponseXMLDoc;
    	
    		_bstr_t svcresp(spServerXMLHTTP1->GetresponseText());
    		spResponseXMLDoc = spServerXMLHTTP1->responseXML;
    		return svcresp;
    	}
    	else
    	{
    		_bstr_t svcresp(W2A(spServerXMLHTTP1->statusText));
    		return svcresp;
    	}
      }
    	catch (char * errmsg)
    	{
    		_bstr_t svcresp (errmsg);
    		return svcresp;
    	}
    	catch (_bstr_t bstrerr)
    	{
    	  	int ierror;
    		char errmsg [100] = {0};
    		ierror = sprintf(errmsg,"Critical Error trying to execute IG Web Service???");
    		_bstr_t svcresp (errmsg);
    		return svcresp;
    	}
    	catch(_com_error e)
    	{
    	  	int templen;
    		char errmsg [1000] = "Critical Error - COM ";
    		_bstr_t bstrErrMsg;
    		bstrErrMsg = ConvertStringToBSTR (e.ErrorMessage());
    		templen = strlen((char *)bstrErrMsg) + 1;
    		memmove(errmsg + 21,(char *) bstrErrMsg, templen);		
    		
    //		ierror = sprintf(errmsg,"Critical Error - COM Error trying to execute IG Web Service???");
    		
    		_bstr_t svcresp (errmsg);
    		return svcresp;
    	}
        catch (unsigned int e)
        {
    	  	int ierror;
    		char errmsg [100] = {0};
            if (e == EXCEPTION_INT_DIVIDE_BY_ZERO)
            {
    			ierror = sprintf(errmsg,"Divide by zero Error trying to execute IG Web Service???");
    			_bstr_t svcresp (errmsg);
    	
    			return svcresp;
            }
            if (e == EXCEPTION_ACCESS_VIOLATION)
            {
    			ierror = sprintf(errmsg,"Access Violation C++ proxy Error");
    			_bstr_t svcresp (errmsg);
    	
    			return svcresp;
            }
            if (e == EXCEPTION_PRIV_INSTRUCTION)
            {
    			ierror = sprintf(errmsg,"Attempt to execute privileged instruction proxy Error");
    			_bstr_t svcresp (errmsg);
    	
    			return svcresp;
            }
            if (e == EXCEPTION_STACK_OVERFLOW)
            {
    			ierror = sprintf(errmsg,"Stack Overflow proxy Error");
    			_bstr_t svcresp (errmsg);
    	
    			return svcresp;
            }
            if (e == EXCEPTION_INT_OVERFLOW)
            {
    			ierror = sprintf(errmsg,"Integer Overflow proxy Error");
    			_bstr_t svcresp (errmsg);
    	
    			return svcresp;
            }
    		ierror = sprintf(errmsg,"Critical Error trying to execute IG Web Service???");
    		_bstr_t svcresp (errmsg);
    		return svcresp;
    	}
    	catch (std::exception& e)
    	{
    	  	int templen;
    		char errmsg [1000] = "Critical Error - COM ";
    		_bstr_t bstrErrMsg;
    		bstrErrMsg = ConvertStringToBSTR (e.what());
    		templen = strlen((char *)bstrErrMsg) + 1;
    		memmove(errmsg + 21,(char *) bstrErrMsg, templen);		
    		
    		_bstr_t svcresp (errmsg);
    		return svcresp;
    	}
    	catch(...)
    	{
    	//TODO: Error handling
    	  	int ierror;
    //		double dwTarget;
    		char errmsg [100] = {0};
    //		dwTarget = AFX_STACK_DUMP_TARGET_CLIPBOARD   
    //        AfxDumpStack(dwTarget);
    		ierror = sprintf(errmsg,"Critical Error trying to execute IG Web Service???");
    		_bstr_t svcresp (errmsg);
    		return svcresp;
    	}
    }

    Any clues?
    Thursday, February 13, 2014 7:51 PM

Answers

All replies

  • I should add that the Windows XP machine it works on is 32-bit, and the Windows Server 2008 R2 machine it doesn't work on is 64-bit.  I'm not sure if that is part of the problem or not.
    Thursday, February 13, 2014 7:55 PM
  • Hello,

    When we call a C++ DLL, we need to register it firstly.

    For register a DLL on Windows 2008 R2 server, we can use the Regsvr32 tool:

    http://support.microsoft.com/kb/249873

    If this does not work for you, please let me know.

    Regards.


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Friday, February 14, 2014 7:42 AM
    Moderator
  • Thanks so much for the reply.  I ran regsvr32 out of the SysWOW64 directory since this is a 32-bit dll on a 64-bit OS.  I get this error:

    The module "IgWebServiceProxy.dll" was loaded but the entry-point DllRegisterServer was not found.  Make sure that "IgWebServiceProxy.dll" is a valid DLL or OCX file and then try again.

    The link you posted gives the following explanation for the error:
    Regsvr32.exe was unable to find the required entry point in the module specified in the command line. This can occur if the entry points are not exported correctly from the module or if the module is not a .DLL or .OCX file.

    I'm not quite sure how to resolve that.  This is not my forte, but I will run some searches and try to figure it out.  If it's something obvious, feel free to chime it!

    Thanks again!

    Friday, February 14, 2014 3:08 PM
  • Hello,

    What type is the IgWebServiceProxy.DLL?

    The error indicates that the DLL is either not a COM DLL or it's corrupt. If it's not a COM DLL and not being used as a COM DLL by an application then there is no need to register it.


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Monday, February 17, 2014 7:44 AM
    Moderator
  • Well, that's a really good point.  It's not a COM dll.  It's just a WIN32 dll, so why would I get this error? 

    It's also interesting to note that I don't get the error when I call IgWebServiceProxy.dll, I get the error INSIDE IgWebServiceProxy.dll when it invokes the CoCreateInstance function. 

    Is there something else I need to register?  Since this works fine on XP, do I need to use a different function on Windows Server 2008?

    Monday, February 17, 2014 2:17 PM
  • >I get the error INSIDE IgWebServiceProxy.dll when it invokes the CoCreateInstance function. 

    >Is there something else I need to register?

    Yes you must install whatever component it's trying to load with CoCreateInstance.  Looks like it's using MSXML40 http://www.microsoft.com/en-us/download/details.aspx?id=15697

    David


    David http://blogs.msdn.com/b/dbrowne/


    Monday, February 17, 2014 3:21 PM
  • I'm sorry.  I didn't write this code, so I'm still trying to understand it.  This is the CoCreateInstance function that is failing:

    HRESULT hr = spServerXMLHTTP1.CoCreateInstance(CLSID_ServerXMLHTTP40);

    CLSID_ServerXMLHTTP40 is defines as follows:

    extern "C" const GUID __declspec(selectany) CLSID_ServerXMLHTTP40 = {0x88d969c6,0xf192,0x11d4,{0xa6,0x5f,0x00,0x40,0x96,0x32,0x51,0xe5}};

    How would I register that?

    Monday, February 17, 2014 3:34 PM
  • CLSID_ServerXMLHTTP40 is part of the MSXML 4.0 package. Just download and install it.

    MSXML40 http://www.microsoft.com/en-us/download/details.aspx?id=15697

    David


    David http://blogs.msdn.com/b/dbrowne/

    • Marked as answer by MarkStein Monday, February 17, 2014 4:40 PM
    Monday, February 17, 2014 4:15 PM
  • That did it!  Thank you so much!!
    Monday, February 17, 2014 4:40 PM