Example #1
0
STDMETHODIMP CBHttpRequest::Read(long nSize, VARIANT *retVal)
{
    DWORD dwTempSize = m_dwDataAvailable;

    if(!m_eventComplete.Wait(0))
        return SetErrorInfo(L"Response is not yet available.");

    if(m_nReadyState < 3)
        return SetErrorInfo(L"Response is not yet available.");

    if(nSize <= 0 || nSize > (long)(dwTempSize - m_dwReadPos))
        nSize = dwTempSize - m_dwReadPos;

    CBVarPtr varPtr;

    varPtr.Create(nSize);

    if(nSize)
    {
        CopyMemory(varPtr.m_pData, m_aBuffer + m_dwReadPos, nSize);
        m_dwReadPos += nSize;
        if(m_dwReadPos == m_dwDataAvailable)
        {
            m_dwDataAvailable = 0;
            m_dwReadPos = 0;

            ReadBuffer();
        }
    }

    return varPtr.GetVariant(retVal);
}
Example #2
0
//重新连接
bool __cdecl CDataBase::TryConnectAgain(bool bFocusConnect, CComError * pComError)
{
	try
	{
		//判断重连
		bool bReConnect = bFocusConnect;
		if (bReConnect == false)
		{
			DWORD dwNowTime = (DWORD)time(NULL);
			if ((m_dwConnectErrorTime + m_dwResumeConnectTime) > dwNowTime) bReConnect = true;
		}
		if ((bReConnect == false) && (m_dwConnectCount > m_dwResumeConnectCount)) bReConnect = true;

		//设置变量
		m_dwConnectCount++;
		m_dwConnectErrorTime = (DWORD)time(NULL);
		if (bReConnect == false)
		{
			if (pComError != NULL) SetErrorInfo(SQLException_Connect, GetComErrorDescribe(*pComError));
			return false;
		}

		//重新连接
		OpenConnection();
		return true;
	}
	catch (IDataBaseException * pIDataBaseException)
	{
		//重新连接错误
		if (pComError != NULL) SetErrorInfo(SQLException_Connect, GetComErrorDescribe(*pComError));
		else throw pIDataBaseException;
	}

	return false;
}
// Given an EXCEPINFO, register the error information with the
// IErrorInfo interface.
BOOL PyCom_SetCOMErrorFromExcepInfo(const EXCEPINFO *pexcepinfo, REFIID riid)
{
	ICreateErrorInfo *pICEI;
	HRESULT hr = CreateErrorInfo(&pICEI);
	if ( SUCCEEDED(hr) )
	{
		pICEI->SetGUID(riid);
		pICEI->SetHelpContext(pexcepinfo->dwHelpContext);
		if ( pexcepinfo->bstrDescription )
			pICEI->SetDescription(pexcepinfo->bstrDescription);
		if ( pexcepinfo->bstrHelpFile )
			pICEI->SetHelpFile(pexcepinfo->bstrHelpFile);
		if ( pexcepinfo->bstrSource )
			pICEI->SetSource(pexcepinfo->bstrSource);

		IErrorInfo *pIEI;
		Py_BEGIN_ALLOW_THREADS
		hr = pICEI->QueryInterface(IID_IErrorInfo, (LPVOID*) &pIEI);
		Py_END_ALLOW_THREADS
		if ( SUCCEEDED(hr) )
		{
			SetErrorInfo(0, pIEI);
			pIEI->Release();
		}
		pICEI->Release();			
	}
	return SUCCEEDED(hr);
}
Example #4
0
//执行语句
VOID __cdecl CDataBase::ExecuteProcess(LPCTSTR pszSPName, bool bRecordset)
{
	ASSERT(pszSPName != NULL);
	try
	{
		//关闭记录集
		CloseRecordset();

		m_DBCommand->CommandText = pszSPName;

		//执行命令
		if (bRecordset == true)
		{
			m_DBRecordset->PutRefSource(m_DBCommand);
			m_DBRecordset->CursorLocation = adUseClient;
			EfficacyResult(m_DBRecordset->Open((IDispatch *)m_DBCommand, vtMissing, adOpenForwardOnly, adLockReadOnly, adOptionUnspecified));
		}
		else
		{
			m_DBConnection->CursorLocation = adUseClient;
			EfficacyResult(m_DBCommand->Execute(NULL, NULL, adExecuteNoRecords));
		}
	}
	catch (CComError & ComError)
	{
		if (IsConnectError() == true)	TryConnectAgain(false, &ComError);
		else SetErrorInfo(SQLException_Syntax, GetComErrorDescribe(ComError));
	}
}
Example #5
0
/**
 * Sets the COM error from a result code and text message. This is the base
 * implementation for subsequent string based overrides
 * @param hResult the COM error code to be used
 * @param message the message to put in the error
 * @return the error code passed in via hResult
 */
static HRESULT Error(HRESULT hResult, const CComBSTR & message)
{
    CComPtr<ICreateErrorInfo> pCreateError;
    CComPtr<IErrorInfo> pError;
    HRESULT result = CreateErrorInfo(&pCreateError);
    if(FAILED(result))
        return E_NOTIMPL;
    result = pCreateError->QueryInterface(&pError);
    if(FAILED(result))
        return E_NOTIMPL;
    result = pCreateError->SetDescription(message);
    if(FAILED(result))
        return E_NOTIMPL;
    result = pCreateError->SetGUID(IID_IDispatch);
    if(FAILED(result))
        return E_NOTIMPL;
    CComBSTR source(L"@mozilla.XPCDispatchTearOff");
    result = pCreateError->SetSource(source);
    if(FAILED(result))
        return E_NOTIMPL;
    result = SetErrorInfo(0, pError);
    if(FAILED(result))
        return E_NOTIMPL;
    return hResult;
}
Example #6
0
HRESULT CALLBACK IRowsetInfo_GetProperties_Proxy(IRowsetInfo* This, const ULONG cPropertyIDSets, const DBPROPIDSET rgPropertyIDSets[],
                                                 ULONG *pcPropertySets, DBPROPSET **prgPropertySets)
{
    HRESULT hr;
    IErrorInfo *error;
    ULONG i;

    TRACE("(%p)->(%d, %p, %p, %p)\n", This, cPropertyIDSets, rgPropertyIDSets, pcPropertySets, prgPropertySets);

    for(i = 0; i < cPropertyIDSets; i++)
    {
        int j;
        TRACE("%d: %s %d props\n", i, debugstr_guid(&rgPropertyIDSets[i].guidPropertySet), rgPropertyIDSets[i].cPropertyIDs);
        for(j = 0; j < rgPropertyIDSets[i].cPropertyIDs; j++)
            TRACE("\t%d: prop id %d\n", j, rgPropertyIDSets[i].rgPropertyIDs[j]);
    }

    hr = IRowsetInfo_RemoteGetProperties_Proxy(This, cPropertyIDSets, rgPropertyIDSets, pcPropertySets, prgPropertySets, &error);

    if(error)
    {
        SetErrorInfo(0, error);
        IErrorInfo_Release(error);
    }
    return hr;
}
Example #7
0
HRESULT CALLBACK IAccessor_CreateAccessor_Proxy(IAccessor* This, DBACCESSORFLAGS dwAccessorFlags, DBCOUNTITEM cBindings,
                                                const DBBINDING rgBindings[], DBLENGTH cbRowSize, HACCESSOR *phAccessor,
                                                DBBINDSTATUS rgStatus[])
{
    HRESULT hr;
    IErrorInfo *error;
    DBCOUNTITEM i;

    TRACE("(%p)->(%08x, %d, %p, %d, %p, %p)\n", This, dwAccessorFlags, cBindings, rgBindings,
          cbRowSize, phAccessor, rgStatus);

    for(i = 0; i < cBindings; i++)
    {
        TRACE("%d: ord %d val off %d len off %d stat off %d part %04x mem_owner %d max_len %d type %04x\n",
              i, rgBindings[i].iOrdinal, rgBindings[i].obValue, rgBindings[i].obLength, rgBindings[i].obStatus,
              rgBindings[i].dwPart, rgBindings[i].dwMemOwner, rgBindings[i].cbMaxLen, rgBindings[i].wType);
    }

    hr = IAccessor_RemoteCreateAccessor_Proxy(This, dwAccessorFlags, cBindings, (DBBINDING *)rgBindings,
                                              cbRowSize, phAccessor, rgStatus, &error);
    if(error)
    {
        SetErrorInfo(0, error);
        IErrorInfo_Release(error);
    }

    TRACE("returning %08x accessor %lx\n", hr, *phAccessor);
    return hr;
}
STDMETHODIMP nsXPCDispTestMethods::CreateError()
{
    CComBSTR someText(L"CreateError Test");
    ICreateErrorInfo * pCreateError;
    IErrorInfo * pError;
    HRESULT result = CreateErrorInfo(&pCreateError);
    if (FAILED(result))
        return E_NOTIMPL;
    result = pCreateError->QueryInterface(&pError);
    if (FAILED(result))
        return E_NOTIMPL;
    result = pCreateError->SetDescription(someText);
    if (FAILED(result))
        return E_NOTIMPL;
    result = pCreateError->SetGUID(IID_nsIXPCDispTestMethods);
    if (FAILED(result))
        return E_NOTIMPL;
    CComBSTR source(L"XPCIDispatchTest.nsXPCDispTestMethods.1");
    result = pCreateError->SetSource(source);
    if (FAILED(result))
        return E_NOTIMPL;
    result = SetErrorInfo(0, pError);
    if (FAILED(result))
        return E_NOTIMPL;
    pError->Release();
    pCreateError->Release();
    return E_FAIL;
}
Example #9
0
HRESULT CALLBACK ISessionProperties_SetProperties_Proxy(ISessionProperties* This, ULONG cPropertySets, DBPROPSET rgPropertySets[])
{
    ULONG prop_set, prop, total_props = 0;
    HRESULT hr;
    IErrorInfo *error;
    DBPROPSTATUS *status;

    TRACE("(%p, %d, %p)\n", This, cPropertySets, rgPropertySets);

    for(prop_set = 0; prop_set < cPropertySets; prop_set++)
        total_props += rgPropertySets[prop_set].cProperties;

    if(total_props == 0) return S_OK;

    status = CoTaskMemAlloc(total_props * sizeof(*status));
    if(!status) return E_OUTOFMEMORY;

    hr = ISessionProperties_RemoteSetProperties_Proxy(This, cPropertySets, rgPropertySets,
                                                      total_props, status, &error);
    if(error)
    {
        SetErrorInfo(0, error);
        IErrorInfo_Release(error);
    }

    total_props = 0;
    for(prop_set = 0; prop_set < cPropertySets; prop_set++)
        for(prop = 0; prop < rgPropertySets[prop_set].cProperties; prop++)
            rgPropertySets[prop_set].rgProperties[prop].dwStatus = status[total_props++];

    CoTaskMemFree(status);
    return hr;
}
Example #10
0
STDMETHODIMP CBHash::get_HashSize(short *pVal)
{
	if(m_iAlgo < 0)return SetErrorInfo(s_strAlgoError);

	*pVal = s_HashAlgos[m_iAlgo].Size;
	return S_OK;
}
Example #11
0
//获取参数
bool __cdecl CDataBase::GetFieldValue(LPCTSTR lpFieldName, INT & nValue)
{
	try
	{
		nValue=0;
		_variant_t vtFld = m_DBRecordset->Fields->GetItem(lpFieldName)->Value;
		switch(vtFld.vt)
		{
		case VT_BOOL:
			{
				nValue = vtFld.boolVal;
				break;
			}
		case VT_I2:
		case VT_UI1:
			{
				nValue = vtFld.iVal;
				break;
			}
		case VT_NULL:
		case VT_EMPTY:
			{
				nValue = 0;
				break;
			}
		default: nValue = vtFld.iVal;
		}	
		return true;
	}
	catch (CComError & ComError) { SetErrorInfo(ErrorType_Other,GetComErrorDescribe(ComError)); }

	return false;
}
Example #12
0
//获取参数
bool __cdecl CDataBase::GetFieldValue(LPCTSTR lpFieldName, bool & bValue)
{
	try
	{
		_variant_t vtFld = m_DBRecordset->Fields->GetItem(lpFieldName)->Value;
		switch (vtFld.vt)
		{
			case VT_BOOL:
			{
				bValue = (vtFld.boolVal == 0) ? false : true;
				break;
			}
			case VT_EMPTY:
			case VT_NULL:
			{
				bValue = false;
				break;
			}
			default:
				return false;
		}
		return true;
	}
	catch (CComError & ComError)
	{
		SetErrorInfo(SQLException_Syntax, GetComErrorDescribe(ComError));
	}

	return false;
}
Example #13
0
//执行命令
bool __cdecl CDataBase::ExecuteCommand(bool bRecordset)
{
	try 
	{
		//关闭记录集
		CloseRecordset();

		//执行命令
		if (bRecordset==true)
		{
			m_DBRecordset->PutRefSource(m_DBCommand);
			m_DBRecordset->CursorLocation=adUseClient;
			EfficacyResult(m_DBRecordset->Open((IDispatch *)m_DBCommand,vtMissing,adOpenForwardOnly,adLockReadOnly,adOptionUnspecified));
		}
		else 
		{
			m_DBConnection->CursorLocation=adUseClient;
			EfficacyResult(m_DBCommand->Execute(NULL,NULL,adExecuteNoRecords));
		}
		return true;
	}
	catch (CComError & ComError) 
	{ 
		if (IsConnectError()==true)	TryConnectAgain(false,&ComError);
		else SetErrorInfo(ErrorType_Other,GetComErrorDescribe(ComError));
	}

	return false;
}
Example #14
0
//获取参数
bool __cdecl CDataBase::GetFieldValue(LPCTSTR lpFieldName, COleDateTime & Time)
{
	try
	{
		_variant_t vtFld = m_DBRecordset->Fields->GetItem(lpFieldName)->Value;
		switch (vtFld.vt)
		{
			case VT_DATE:
			{
				COleDateTime TempTime(vtFld);
				Time = TempTime;
				break;
			}
			case VT_EMPTY:
			case VT_NULL:
			{
				Time.SetStatus(COleDateTime::null);
				break;
			}
			default:
				return false;
		}
		return true;
	}
	catch (CComError & ComError)
	{
		SetErrorInfo(SQLException_Syntax, GetComErrorDescribe(ComError));
	}

	return false;
}
Example #15
0
//
//
//   makes an HRESULT with a code based on the DOM error code
//
HRESULT MakeHRESULT(DOMException& ex)
{
	ICreateErrorInfo* pCErr = NULL;
	HRESULT sc = CreateErrorInfo(&pCErr);
	if(SUCCEEDED(sc)) {
		const XMLCh* msg = ex.msg;
		if(msg == NULL)
		{
			if(ex.code >= DOMException::INDEX_SIZE_ERR &&
				ex.code <= DOMException::VALIDATION_ERR)
			{
				sc = pCErr->SetDescription(Msgs[ex.code]);
			}
			else
			{
				sc = pCErr->SetDescription(Msgs[0]);
			}
		}
		else
		{
			sc = pCErr->SetDescription(SysAllocString(ex.msg));
		}

		IErrorInfo* pErr = NULL;
		sc = pCErr->QueryInterface(IID_IErrorInfo,(void**) &pErr);
		if(SUCCEEDED(sc))
		{
			sc = SetErrorInfo(0,pErr);
			pErr->Release();
		}
		pCErr->Release();
	}
	return 0x80040600 + ex.code;
}
Example #16
0
STDMETHODIMP CBHttpRequest::Write(const void *pv, ULONG cb, ULONG *pcbWritten)
{
    if(m_nReadyState != 1)
        return SetErrorInfo(L"Request not initialized.");

    return m_mStream.Write(pv, cb, pcbWritten);
}
Example #17
0
// The CreateComErrorInfo function uses CreateErrorInfo to create error
// object, which is then filled with the error information and passed to
// the acceptor by a call to SetErrorInfo.
void CreateComErrorInfo(const char* description, const char* source,
  const char* helpFile, UInt32 helpContext)
{
  ICreateErrorInfo* createErrInfo;
  IErrorInfo* errInfo;
  std::basic_string<wchar_t> buf;
  if (CreateErrorInfo(&createErrInfo) == S_OK)
  {
    createErrInfo->SetGUID(IID_IErrorInfo);
    if (description != NULL)
    {
      buf = WideStringFromMultiByteString(description);
      createErrInfo->SetDescription(const_cast<wchar_t*>(buf.c_str()));
    }
    if (source != NULL)
    {
      buf = WideStringFromMultiByteString(source);
      createErrInfo->SetSource(const_cast<wchar_t*>(buf.c_str()));
    }
    if (helpFile != NULL)
    {
      buf = WideStringFromMultiByteString(helpFile);
      createErrInfo->SetHelpFile(const_cast<wchar_t*>(buf.c_str()));
    }
    createErrInfo->SetHelpContext(helpContext);
    if (createErrInfo->QueryInterface(IID_IErrorInfo, (void**)(&errInfo)) == S_OK)
    {
      SetErrorInfo(0, errInfo);
      errInfo->Release();
    }
    createErrInfo->Release();
  }
}
Example #18
0
STDMETHODIMP CXRecords::Sort(VARIANT key, VARIANT varAsc)
{
	if(!m_pFields)return SetErrorInfo(s_errInit);

	int pos, bAsc;

	int count = m_listRecords->GetCount();

	if(count == 0)
		return S_OK;

	pos = m_pFields->FindField(key);
	if(pos < 0 || pos >= (int)m_pFields->GetCount())
		return DISP_E_BADINDEX;

	bAsc = varGetNumbar(varAsc, 1);

	s_csSort.Enter();
	s_posSort = pos;
	s_bAscSort = bAsc ? 1 : -1;

	qsort(&m_listRecords->GetValue(0), count, sizeof(CXComPtr<CXRecord>), sortProc);

	s_csSort.Leave();

	return S_OK;
}
Example #19
0
HRESULT CXRecords::Save(IStream* pFile)
{
	if(!m_pFields)return SetErrorInfo(s_errInit);

	CXStream StreamStub(pFile);
	HRESULT hr;
	int i, count, count1;

	W(m_nDocFormat);

	if(m_nDocFormat == -1)
	{
		count = m_pFields->GetCount();
		W(count);

		for(i = 0; i < count; i ++)
		{
			W(m_pFields->GetValue(i)->m_strName);
			W(m_pFields->GetValue(i)->m_nType);
		}
	}

	count1 = m_listRecords->GetCount();
	W(count1);

	for(i = 0; i < count1; i ++)
	{
		hr = m_listRecords->GetValue(i)->Save(pFile);
		if(FAILED(hr))return hr;
	}

	return S_OK;
}
Example #20
0
STDMETHODIMP CXRecords::Remove(int pos)
{
	if(!m_pFields)return SetErrorInfo(s_errInit);

	m_listRecords->RemoveAt(pos);
	return S_OK;
}
Example #21
0
HRESULT
COMError::GenerateError(HM::String sDescription)
{
   if (sDescription == _T(""))
   {
      sDescription = "The operation failed. Please check the hMailServer log for details.";
   }

   // Get the ICreateErrorInfo Interface
   ICreateErrorInfo *pCreateErrorInfo = NULL;
   HRESULT hSuccess = CreateErrorInfo(&pCreateErrorInfo);
   ATLASSERT(SUCCEEDED(hSuccess));
   // pCreateErrorInfo->SetGUID(CLSID_BaseApp);
   pCreateErrorInfo->SetDescription(sDescription.AllocSysString());
   HM::String sSource = "hMailServer COM library";
   pCreateErrorInfo->SetSource(sSource.AllocSysString());

   IErrorInfo *pErrInfo;

   if (SUCCEEDED(pCreateErrorInfo->QueryInterface(IID_IErrorInfo, 
      reinterpret_cast<void**>(&pErrInfo))))
   {
      SetErrorInfo(0, pErrInfo);
      pErrInfo->Release();
   }

   pCreateErrorInfo->Release();

   return MAKE_HRESULT(1, FACILITY_ITF, 1001);
}
Example #22
0
STDMETHODIMP CXRecords::GetRows(VARIANT key, VARIANT* pVal)
{
	if(!m_pFields)return SetErrorInfo(s_errInit);

	CComSafeArray<VARIANT> bstrArray;
	VARIANT* pVar;
	HRESULT hr;
	int i = 0;
	int pos;
	int count = m_listRecords->GetCount();

	pos = m_pFields->FindField(key);
	if(pos < 0 || pos >= (int)m_pFields->GetCount())
		return DISP_E_BADINDEX;

	hr = bstrArray.Create(count);
	if(FAILED(hr))return hr;

	pVar = (VARIANT*)bstrArray.m_psa->pvData;

	for(i = 0; i < count; i ++)
	{
		hr = VariantCopy(&pVar[i], (VARIANT*)&m_listRecords->GetValue(i)->m_arrayVariant[pos]);
		if(FAILED(hr))
		{
			bstrArray.Destroy();
			return hr;
		}
	}

	pVal->vt = VT_ARRAY | VT_VARIANT;
	pVal->parray = bstrArray.Detach();

	return S_OK;
}
Example #23
0
//是否连接错误
bool __cdecl CDataBase::IsConnectError()
{
	try
	{
		//状态判断
		if (m_DBConnection == NULL) return true;
		if (m_DBConnection->GetState() == adStateClosed) return true;

		//参数判断
		long lErrorCount = m_DBConnection->Errors->Count;
		if (lErrorCount > 0L)
		{
			ErrorPtr pError = NULL;
			for (long i = 0; i < lErrorCount; i++)
			{
				pError = m_DBConnection->Errors->GetItem(i);
				if (pError->Number == 0x80004005) return true;
			}
		}

		return false;
	}
	catch (CComError & ComError)
	{
		SetErrorInfo(SQLException_Syntax, GetComErrorDescribe(ComError));
	}

	return false;
}
Example #24
0
void SqlConnection::AcquireErrorInfo() {
    if (m_mysql != nullptr) {
        const auto errorCode = mysql_errno(m_mysql);
        const auto errorMsg = mysql_error(m_mysql);
        SetErrorInfo(errorCode, errorMsg);
    }
}
Example #25
0
STDMETHODIMP CBHash::Final(VARIANT varData, VARIANT *retVal)
{
	if(m_iAlgo < 0)return SetErrorInfo(s_strAlgoError);

	if(varData.vt != VT_ERROR)
		Update(varData);

	CBVarPtr varPtr;

	varPtr.Create(s_HashAlgos[m_iAlgo].Size);
	
	if (s_HashAlgos[m_iAlgo].evp_md)
	{
		unsigned long size;
		((void (*)(void *, const unsigned char *, unsigned long *))(void *)s_HashAlgos[m_iAlgo].Final)(&m_ctx, varPtr.m_pData, &size);
		((void (*)(void *, const unsigned char *, unsigned long, void *))(void *)s_HashAlgos[m_iAlgo].Init)(&m_ctx, m_varKey.m_pData, m_varKey.m_nSize, (void *)s_HashAlgos[m_iAlgo].evp_md());
	}
	else
	{
		s_HashAlgos[m_iAlgo].Final(varPtr.m_pData, &m_ctx);
		s_HashAlgos[m_iAlgo].Init(&m_ctx);
	}

	return varPtr.GetVariant(retVal);
}
Example #26
0
STDMETHODIMP CBCipher::get_Name(BSTR *pVal)
{
	if(!m_ctx.cipher)return SetErrorInfo(s_strAlgoError);

	*pVal = CBString(OBJ_nid2sn(EVP_CIPHER_CTX_nid(&m_ctx))).AllocSysString();

	return S_OK;
}
Example #27
0
STDMETHODIMP CBCipher::get_KeySize(short *pVal)
{
	if(!m_ctx.cipher)return SetErrorInfo(s_strAlgoError);

	*pVal = EVP_CIPHER_CTX_key_length(&m_ctx);

	return S_OK;
}
Example #28
0
STDMETHODIMP CBHash::get_Name(BSTR *pVal)
{
	if(m_iAlgo < 0)return SetErrorInfo(s_strAlgoError);

	*pVal = ::SysAllocString(s_HashAlgos[m_iAlgo].Name);

	return S_OK;
}
Example #29
0
STDMETHODIMP CBCipher::get_CipherMode(short *pVal)
{
	if(!m_ctx.cipher)return SetErrorInfo(s_strAlgoError);

	*pVal = (short)EVP_CIPHER_CTX_mode(&m_ctx);

	return S_OK;
}
Example #30
0
STDMETHODIMP CBCipher::get_BlockSize(short *pVal)
{
	if(!m_ctx.cipher)return SetErrorInfo(s_strAlgoError);

	*pVal = EVP_CIPHER_CTX_block_size(&m_ctx);

	return S_OK;
}