Esempio n. 1
0
VariantVector Deserializer::ReadVariantVector()
{
    VariantVector ret(ReadVLE());
    for (unsigned i = 0; i < ret.Size(); ++i)
        ret[i] = ReadVariant();
    return ret;
}
Esempio n. 2
0
VariantMap Deserializer::ReadVariantMap()
{
    VariantMap ret;
    unsigned num = ReadVLE();

    for (unsigned i = 0; i < num; ++i)
    {
        StringHash key = ReadStringHash();
        ret[key] = ReadVariant();
    }

    return ret;
}
Esempio n. 3
0
Variant Deserializer::ReadVariant()
{
    VariantType type = (VariantType)ReadUByte();
    return ReadVariant(type);
}
HRESULT CTCPropBagOnRegKey::_ReadSafeArray(CRegKey& key,
  const _bstr_t& strPropName, VARIANT* pVar, IErrorLog* pErrorLog)
{
  // Open the subkey with the specified name
  CRegKey subkey;
  VERIFY(subkey.Open(key, strPropName));

  // Read the variant type of the registry value
  VARTYPE vt = GetSubkeyVarType(key, strPropName);
  ASSERT(vt & VT_ARRAY);

  // Remove the VT_ARRAY bit flag from the variant type
  vt &= ~VT_ARRAY;

  // Check for supported variant types
  switch (vt)
  {
    case VT_BOOL:
    case VT_I1:
    case VT_I2:
    case VT_I4:
    case VT_UI1:
    case VT_UI2:
    case VT_UI4:
    case VT_ERROR:
    case VT_R4:
    case VT_R8:
    case VT_DECIMAL:
    case VT_CY:
    case VT_DATE:
    case VT_BSTR:
    case VT_UNKNOWN:
    case VT_DISPATCH:
    case VT_VARIANT:
      break;
    default:
    {
      // Use local resources
      MCLibRes res;

      // Format a description string
      _bstr_t strDesc;
      strDesc.Format(IDS_FMT_UNSUP_ARRAY_VARTYPE, strPropName, vt, vt);

      // Log the error
      USES_CONVERSION;
      return LogError("ReadSafeArray", strDesc, E_UNEXPECTED,
        T2COLE(strPropName), pErrorLog);
    }
  }

  // Read the element count of the safe array
  DWORD dwElements = 0;
  if (!subkey.GetDWord(m_szElementCount, dwElements))
  {
    // Use local resources
    MCLibRes res;

    // Format a description string
    _bstr_t strDesc;
    strDesc.Format(IDS_FMT_VALUE_NOT_EXIST, m_szElementCount, strPropName);

    // Log the error
    USES_CONVERSION;
    return LogError("ReadSafeArray", strDesc, E_UNEXPECTED,
      T2COLE(strPropName), pErrorLog);
  }

  // Read the lower bound of the safe array, defaults to zero
  LONG lLBound = 0;
  subkey.GetDWord(m_szLowerBound, (DWORD&)lLBound);

  // Read each array element into a temporary array
  _bstr_t strText;
  CComVariant var;
  CArray<CComVariant, CComVariant&> arrayTemp;
  for (DWORD i = 0; i < dwElements; i++)
  {
    // Prepare the variant
    V_VT(&var) = vt;

    // Format the value name
    strText.Format(m_szElementFmt, i);

    // Read the variant
    HRESULT hr = ReadVariant(subkey, strText, var, pErrorLog);
    if (FAILED(hr))
      return hr;

    // Add the variant to the temporary array
    arrayTemp.Add(var);
  }

  // Create a safe array and copy the temporary array elements
  SAFEARRAY* psa = SafeArrayCreateVector(vt, lLBound, dwElements);
  if (NULL == psa)
  {
    // Use local resources
    MCLibRes res;

    // Format a description string
    _bstr_t strDesc(LPCSTR(IDS_FAIL_SAFEARRAY_CREATE));

    // Log the error
    USES_CONVERSION;
    return LogError("ReadSafeArray", strDesc, E_OUTOFMEMORY,
      T2COLE(strPropName), pErrorLog);
  }

  // Copy the temporary array elements into the safe array
  for (long iElement = 0; iElement < arrayTemp.GetSize(); iElement++)
  {
    CComVariant& v = arrayTemp[iElement];
    void* pvData;
    switch (vt)
    {
      case VT_VARIANT:
        pvData = &v;
        break;
      case VT_UNKNOWN:
      case VT_DISPATCH:
      case VT_BSTR:
        pvData = V_BSTR(&v);
        break;
      default:
        pvData = &V_NONE(&v);
    }

    HRESULT hr = SafeArrayPutElement(psa, &iElement, pvData);
    if (FAILED(hr))
    {
      // Use local resources
      MCLibRes res;

      // Format a description string
      _bstr_t strDesc(LPCSTR(IDS_FAIL_SAFEARRAY_PUT));

      // Log the error
      USES_CONVERSION;
      return LogError("ReadSafeArray", strDesc, hr, T2COLE(strPropName),
        pErrorLog);
    }
  }

  // Put the safe array into the specified variant
  V_VT(pVar) = vt | VT_ARRAY;
  V_ARRAY(pVar) = psa;

  // Indicate success
  return S_OK;
}