Ejemplo n.º 1
0
static HRESULT WINAPI DEVENUM_IPropertyBag_Write(
    LPPROPERTYBAG iface,
    LPCOLESTR pszPropName,
    VARIANT* pVar)
{
    RegPropBagImpl *This = impl_from_IPropertyBag(iface);
    LPVOID lpData = NULL;
    DWORD cbData = 0;
    DWORD dwType = 0;
    HRESULT res = S_OK;

    TRACE("(%p)->(%s, %p)\n", This, debugstr_w(pszPropName), pVar);

    switch (V_VT(pVar))
    {
    case VT_BSTR:
    case VT_LPWSTR:
        TRACE("writing %s\n", debugstr_w(V_BSTR(pVar)));
        lpData = V_BSTR(pVar);
        dwType = REG_SZ;
        cbData = (lstrlenW(V_BSTR(pVar)) + 1) * sizeof(WCHAR);
        break;
    case VT_I4:
    case VT_UI4:
        TRACE("writing %u\n", V_UI4(pVar));
        lpData = &V_UI4(pVar);
        dwType = REG_DWORD;
        cbData = sizeof(DWORD);
        break;
    case VT_ARRAY | VT_UI1:
    {
        LONG lUbound = 0;
        LONG lLbound = 0;
        dwType = REG_BINARY;
        res = SafeArrayGetLBound(V_ARRAY(pVar), 1, &lLbound);
        res = SafeArrayGetUBound(V_ARRAY(pVar), 1, &lUbound);
        cbData = (lUbound - lLbound + 1) /* * sizeof(BYTE)*/;
        TRACE("cbData: %d\n", cbData);
        res = SafeArrayAccessData(V_ARRAY(pVar), &lpData);
        break;
    }
    default:
        FIXME("Variant type %d not handled\n", V_VT(pVar));
        return E_FAIL;
    }

    if (RegSetValueExW(This->hkey,
                       pszPropName, 0,
                       dwType, lpData, cbData) != ERROR_SUCCESS)
        res = E_FAIL;

    if (V_VT(pVar) & VT_ARRAY)
        res = SafeArrayUnaccessData(V_ARRAY(pVar));

    return res;
}
Ejemplo n.º 2
0
static HRESULT WINAPI dcinfo_GetInfo(IDCInfo *iface, ULONG num, DCINFOTYPE types[], DCINFO **info_ptr)
{
    convert *This = impl_from_IDCInfo(iface);
    ULONG i;
    DCINFO *infos;

    TRACE("(%p)->(%d, %p, %p)\n", This, num, types, info_ptr);

    *info_ptr = infos = CoTaskMemAlloc(num * sizeof(*infos));
    if(!infos) return E_OUTOFMEMORY;

    for(i = 0; i < num; i++)
    {
        infos[i].eInfoType = types[i];
        VariantInit(&infos[i].vData);

        switch(types[i])
        {
        case DCINFOTYPE_VERSION:
            V_VT(&infos[i].vData) = VT_UI4;
            V_UI4(&infos[i].vData) = This->version;
            break;
        }
    }

    return S_OK;
}
Ejemplo n.º 3
0
static HRESULT WINAPI dcinfo_SetInfo(IDCInfo* iface, ULONG num, DCINFO info[])
{
    convert *This = impl_from_IDCInfo(iface);
    ULONG i;
    HRESULT hr = S_OK;

    TRACE("(%p)->(%d, %p)\n", This, num, info);

    for(i = 0; i < num; i++)
    {
        switch(info[i].eInfoType)
        {
        case DCINFOTYPE_VERSION:
            if(V_VT(&info[i].vData) != VT_UI4)
            {
                FIXME("VERSION with vt %x\n", V_VT(&info[i].vData));
                hr = DB_S_ERRORSOCCURRED;
                break;
            }
            This->version = V_UI4(&info[i].vData);
            break;

        default:
            FIXME("Unhandled info type %d (vt %x)\n", info[i].eInfoType, V_VT(&info[i].vData));
        }
    }
    return hr;
}
Ejemplo n.º 4
0
static LONG get_var_int(const VARIANT *var)
{
    switch(V_VT(var))
    {
    case VT_I1:
    case VT_UI1:
        return V_UI1(var);

    case VT_I2:
    case VT_UI2:
        return V_UI2(var);

    case VT_I4:
    case VT_UI4:
        return V_UI4(var);

    case VT_I8:
    case VT_UI8:
        return V_UI8(var);

    case VT_INT:
    case VT_UINT:
        return V_UINT(var);

    default:
        FIXME("unsupported variant type %d\n", V_VT(var));
        return 0;
    }
}
Ejemplo n.º 5
0
STDMETHODIMP CZ80Assembler::AddDefine(BSTR bstrName, VARIANT varValue)
{
	if (V_VT(&varValue) == VT_EMPTY || V_VT(&varValue) == VT_ERROR)
	{
		V_VT(&varValue) = VT_UI4;
		V_UI4(&varValue) = 1;
	}

	VARIANT varDefine;
	VariantInit(&varDefine);
	V_VT(&varDefine) = VT_BSTR;
	V_BSTR(&varDefine) = SysAllocString(L"");
	HRESULT hr = VariantChangeType(&varDefine, &varValue, 0, VT_BSTR);
	if (FAILED(hr))
	{
		return hr;
	}

	CW2A szName(bstrName);

	bool fRedefined = false;
	define_t *define = add_define(strdup(szName), &fRedefined);

	if (define != NULL)
	{
		CW2A szContents(V_BSTR(&varDefine));
		define->contents = strdup(szContents);
		return S_OK;
	}
	else
	{
		return E_FAIL;
	}
}
Ejemplo n.º 6
0
static const char *debugstr_variant(const VARIANT *var)
{
    static char buf[400];

    if (!var)
        return "(null)";

    switch (V_VT(var))
    {
    case VT_EMPTY:
        return "{VT_EMPTY}";
    case VT_BSTR:
        sprintf(buf, "{VT_BSTR: %s}", wine_dbgstr_w(V_BSTR(var)));
        break;
    case VT_BOOL:
        sprintf(buf, "{VT_BOOL: %x}", V_BOOL(var));
        break;
    case VT_UI4:
        sprintf(buf, "{VT_UI4: %u}", V_UI4(var));
        break;
    default:
        sprintf(buf, "{vt %d}", V_VT(var));
        break;
    }

    return buf;
}
Ejemplo n.º 7
0
const char *debugstr_variant(const VARIANT *v)
{
    if(!v)
        return "(null)";

    if(V_ISBYREF(v))
        return wine_dbg_sprintf("{V_BYREF -> %s}", debugstr_variant(V_BYREF(v)));

    switch(V_VT(v)) {
    case VT_EMPTY:
        return "{VT_EMPTY}";
    case VT_NULL:
        return "{VT_NULL}";
    case VT_I2:
        return wine_dbg_sprintf("{VT_I2: %d}", V_I2(v));
    case VT_I4:
        return wine_dbg_sprintf("{VT_I4: %d}", V_I4(v));
    case VT_UI4:
        return wine_dbg_sprintf("{VT_UI4: %u}", V_UI4(v));
    case VT_R8:
        return wine_dbg_sprintf("{VT_R8: %lf}", V_R8(v));
    case VT_BSTR:
        return wine_dbg_sprintf("{VT_BSTR: %s}", debugstr_w(V_BSTR(v)));
    case VT_DISPATCH:
        return wine_dbg_sprintf("{VT_DISPATCH: %p}", V_DISPATCH(v));
    case VT_BOOL:
        return wine_dbg_sprintf("{VT_BOOL: %x}", V_BOOL(v));
    default:
        return wine_dbg_sprintf("{vt %d}", V_VT(v));
    }
}
Ejemplo n.º 8
0
static HRESULT DXDiag_InitDXDiagSystemInfoContainer(IDxDiagContainer* pSubCont) {
    HRESULT hr = S_OK;
    static const WCHAR dwDirectXVersionMajor[] = {'d','w','D','i','r','e','c','t','X','V','e','r','s','i','o','n','M','a','j','o','r',0};
    static const WCHAR dwDirectXVersionMinor[] = {'d','w','D','i','r','e','c','t','X','V','e','r','s','i','o','n','M','i','n','o','r',0};
    static const WCHAR szDirectXVersionLetter[] = {'s','z','D','i','r','e','c','t','X','V','e','r','s','i','o','n','L','e','t','t','e','r',0};
    static const WCHAR szDirectXVersionLetter_v[] = {'c',0};
    static const WCHAR bDebug[] = {'b','D','e','b','u','g',0};
    static const WCHAR szDirectXVersionEnglish[] = {'s','z','D','i','r','e','c','t','X','V','e','r','s','i','o','n','E','n','g','l','i','s','h',0};
    static const WCHAR szDirectXVersionEnglish_v[] = {'4','.','0','9','.','0','0','0','0','.','0','9','0','4',0};
    static const WCHAR szDirectXVersionLongEnglish[] = {'s','z','D','i','r','e','c','t','X','V','e','r','s','i','o','n','L','o','n','g','E','n','g','l','i','s','h',0};
    static const WCHAR szDirectXVersionLongEnglish_v[] = {'=',' ','"','D','i','r','e','c','t','X',' ','9','.','0','c',' ','(','4','.','0','9','.','0','0','0','0','.','0','9','0','4',')',0};
    /*static const WCHAR szDxDiagVersion[] = {'s','z','D','x','D','i','a','g','V','e','r','s','i','o','n',0};*/
    /*szWindowsDir*/
    /*szWindowsDir*/
    /*"dwOSMajorVersion"*/
    /*"dwOSMinorVersion"*/
    /*"dwOSBuildNumber"*/
    /*"dwOSPlatformID"*/
    VARIANT v;

    V_VT(&v) = VT_UI4;
    V_UI4(&v) = 9;
    hr = IDxDiagContainerImpl_AddProp(pSubCont, dwDirectXVersionMajor, &v);
    VariantClear(&v);
    V_VT(&v) = VT_UI4;
    V_UI4(&v) = 0;
    hr = IDxDiagContainerImpl_AddProp(pSubCont, dwDirectXVersionMinor, &v);
    VariantClear(&v);
    V_VT(&v) = VT_BSTR;
    V_BSTR(&v) = SysAllocString(szDirectXVersionLetter_v);
    hr = IDxDiagContainerImpl_AddProp(pSubCont, szDirectXVersionLetter, &v);
    VariantClear(&v);
    V_VT(&v) = VT_BSTR;
    V_BSTR(&v) = SysAllocString(szDirectXVersionEnglish_v);
    hr = IDxDiagContainerImpl_AddProp(pSubCont, szDirectXVersionEnglish, &v);
    VariantClear(&v);
    V_VT(&v) = VT_BSTR;
    V_BSTR(&v) = SysAllocString(szDirectXVersionLongEnglish_v);
    hr = IDxDiagContainerImpl_AddProp(pSubCont, szDirectXVersionLongEnglish, &v);
    VariantClear(&v);
    V_VT(&v) = VT_BOOL;
    V_BOOL(&v) = FALSE;
    hr = IDxDiagContainerImpl_AddProp(pSubCont, bDebug, &v);
    VariantClear(&v);

    return hr;
}
Ejemplo n.º 9
0
static inline HRESULT add_prop_ui4( IDxDiagContainer* cont, LPCWSTR prop, DWORD data )
{
    VARIANT var;

    V_VT( &var ) = VT_UI4;
    V_UI4( &var ) = data;
    return IDxDiagContainerImpl_AddProp( cont, prop, &var );
}
Ejemplo n.º 10
0
HRESULT CTCPropBagOnRegKey::_ReadVariantFromValue(CRegKey& key,
  const _bstr_t& strPropName, DWORD nType, int cbData, CComVariant& v,
  IErrorLog* pErrorLog)
{
  // Read the value from the registry based on the value type
  switch (nType)
  {
    case REG_DWORD:
    {
      key.GetDWord(strPropName, (DWORD&)V_UI4(&v));
      v.vt = VT_UI4;
      break;
    }

    case REG_SZ:
    {
      _bstr_t strValue;
      key.GetString(strPropName, strValue);
      v = strValue;
      break;
    }

    case REG_BINARY:
    {
      BYTE* pData = new BYTE[cbData];
      key.GetBinary(strPropName, pData, cbData);
      CMemFile file(pData, cbData);
      CArchive ar(&file, CArchive::load, 0);
      ar >> v;
      ar.Close();
      delete [] file.Detach();
      break;
    }

    default:
    {
      // Use local resources
      MCLibRes res;

      // Format a description string
      _bstr_t strDesc;
      strDesc.Format(IDS_FMT_UNSUPPORTED_REGTYPE, nType);

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

  // Indicate success
  return S_OK;
}
Ejemplo n.º 11
0
void CXmlElement::AddAttribute(LPWSTR pwszName, ULONG ulValue)
{
    HRESULT             hr = S_OK;
    VARIANT             varValue;

    ::VariantInit(&varValue);

    varValue.vt = VT_UI4;
    V_UI4(&varValue) = ulValue;

    hr = AddAttributeInternal(pwszName, varValue);

    ::VariantClear(&varValue);
}
Ejemplo n.º 12
0
DWORD COcsWmi::dwCimValue(VARIANT &pVal, CIMTYPE &pType)

{

	if ((pVal.vt == VT_NULL) || (pVal.vt == VT_EMPTY))

		return 0;

	else

		switch (pType)

		{

		case CIM_SINT8:

			return V_I1(&pVal);

		case CIM_UINT8:

			return V_UI1(&pVal);

		case CIM_SINT16:

			return V_I2(&pVal);

		case CIM_UINT16:

			return V_UI2(&pVal);

		case CIM_SINT32:

			return V_I4(&pVal);

		case CIM_UINT32:

			return V_UI4(&pVal);

		case CIM_BOOLEAN:

			return (V_BOOL(&pVal) ? 1 : 0);

		default:

			return 0;

		}

}
Ejemplo n.º 13
0
HRESULT process_get_owner( IWbemClassObject *obj, IWbemClassObject *in, IWbemClassObject **out )
{
    VARIANT user, domain, retval;
    IWbemClassObject *sig, *out_params = NULL;
    HRESULT hr;

    TRACE("%p, %p, %p\n", obj, in, out);

    hr = create_signature( class_processW, method_getownerW, PARAM_OUT, &sig );
    if (hr != S_OK) return hr;

    if (out)
    {
        hr = IWbemClassObject_SpawnInstance( sig, 0, &out_params );
        if (hr != S_OK)
        {
            IWbemClassObject_Release( sig );
            return hr;
        }
    }
    VariantInit( &user );
    VariantInit( &domain );
    hr = get_owner( &user, &domain, &retval );
    if (hr != S_OK) goto done;
    if (out_params)
    {
        if (!V_UI4( &retval ))
        {
            hr = IWbemClassObject_Put( out_params, param_userW, 0, &user, CIM_STRING );
            if (hr != S_OK) goto done;
            hr = IWbemClassObject_Put( out_params, param_domainW, 0, &domain, CIM_STRING );
            if (hr != S_OK) goto done;
        }
        hr = IWbemClassObject_Put( out_params, param_returnvalueW, 0, &retval, CIM_UINT32 );
    }

done:
    VariantClear( &user );
    VariantClear( &domain );
    IWbemClassObject_Release( sig );
    if (hr == S_OK && out)
    {
        *out = out_params;
        IWbemClassObject_AddRef( out_params );
    }
    if (out_params) IWbemClassObject_Release( out_params );
    return hr;
}
Ejemplo n.º 14
0
HRESULT reg_get_stringvalue( IWbemClassObject *obj, IWbemClassObject *in, IWbemClassObject **out )
{
    VARIANT defkey, subkey, name, value, retval;
    IWbemClassObject *sig;
    HRESULT hr;

    TRACE("%p, %p\n", in, out);

    hr = IWbemClassObject_Get( in, param_defkeyW, 0, &defkey, NULL, NULL );
    if (hr != S_OK) return hr;
    hr = IWbemClassObject_Get( in, param_subkeynameW, 0, &subkey, NULL, NULL );
    if (hr != S_OK) return hr;
    hr = IWbemClassObject_Get( in, param_valuenameW, 0, &name, NULL, NULL );
    if (hr != S_OK) return hr;

    hr = create_signature( class_stdregprovW, method_getstringvalueW, PARAM_OUT, &sig );
    if (hr != S_OK)
    {
        VariantClear( &name );
        VariantClear( &subkey );
        return hr;
    }
    hr = IWbemClassObject_SpawnInstance( sig, 0, out );
    if (hr != S_OK)
    {
        VariantClear( &name );
        VariantClear( &subkey );
        IWbemClassObject_Release( sig );
        return hr;
    }
    VariantInit( &value );
    hr = get_stringvalue( (HKEY)(INT_PTR)V_I4(&defkey), V_BSTR(&subkey), V_BSTR(&name), &value, &retval );
    if (hr != S_OK) goto done;
    if (!V_UI4( &retval ))
    {
        hr = IWbemClassObject_Put( *out, param_valueW, 0, &value, CIM_STRING );
        if (hr != S_OK) goto done;
    }
    hr = IWbemClassObject_Put( *out, param_returnvalueW, 0, &retval, CIM_UINT32 );

done:
    VariantClear( &name );
    VariantClear( &subkey );
    IWbemClassObject_Release( sig );
    if (hr != S_OK) IWbemClassObject_Release( *out );
    return hr;
}
Ejemplo n.º 15
0
static void test_Win32_Service( IWbemServices *services )
{
    static const WCHAR returnvalueW[] = {'R','e','t','u','r','n','V','a','l','u','e',0};
    static const WCHAR pauseserviceW[] = {'P','a','u','s','e','S','e','r','v','i','c','e',0};
    static const WCHAR resumeserviceW[] = {'R','e','s','u','m','e','S','e','r','v','i','c','e',0};
    static const WCHAR startserviceW[] = {'S','t','a','r','t','S','e','r','v','i','c','e',0};
    static const WCHAR stopserviceW[] = {'S','t','o','p','S','e','r','v','i','c','e',0};
    static const WCHAR stateW[] = {'S','t','a','t','e',0};
    static const WCHAR stoppedW[] = {'S','t','o','p','p','e','d',0};
    static const WCHAR serviceW[] = {'W','i','n','3','2','_','S','e','r','v','i','c','e','.',
                                     'N','a','m','e','=','"','S','p','o','o','l','e','r','"',0
                                    };
    static const WCHAR emptyW[] = {0};
    BSTR class = SysAllocString( serviceW ), empty = SysAllocString( emptyW ), method;
    IWbemClassObject *service, *out;
    VARIANT state, retval;
    CIMTYPE type;
    HRESULT hr;

    hr = IWbemServices_GetObject( services, class, 0, NULL, &service, NULL );
    if (hr != S_OK)
    {
        win_skip( "Win32_Service not available\n" );
        goto out;
    }
    type = 0xdeadbeef;
    VariantInit( &state );
    hr = IWbemClassObject_Get( service, stateW, 0, &state, &type, NULL );
    ok( hr == S_OK, "failed to get service state %08x\n", hr );
    ok( V_VT( &state ) == VT_BSTR, "unexpected variant type 0x%x\n", V_VT( &state ) );
    ok( type == CIM_STRING, "unexpected type 0x%x\n", type );

    if (!lstrcmpW( V_BSTR( &state ), stoppedW ))
    {
        out = NULL;
        method = SysAllocString( startserviceW );
        hr = IWbemServices_ExecMethod( services, class, method, 0, NULL, NULL, &out, NULL );
        ok( hr == S_OK, "failed to execute method %08x\n", hr );
        SysFreeString( method );

        VariantInit( &retval );
        hr = IWbemClassObject_Get( out, returnvalueW, 0, &retval, NULL, NULL );
        ok( hr == S_OK, "failed to get return value %08x\n", hr );
        ok( !V_I4( &retval ), "unexpected error %u\n", V_UI4( &retval ) );
        IWbemClassObject_Release( out );
    }
Ejemplo n.º 16
0
ListOfCS::iterator	CTRiASCSSet::FindItem( const VARIANT& Item ) 
{
ListOfCS::iterator i = m_listOfCS.end();

	if( V_ISUNKNOWN(&Item) ) {
		i = find( m_listOfCS.begin(), m_listOfCS.end(), WTRiASCS( V_UNKNOWN(&Item) ) );
	} else if( V_ISDISPATCH(&Item) ) {
		i = find( m_listOfCS.begin(), m_listOfCS.end(), WTRiASCS( V_DISPATCH(&Item) ) );
	} else if( V_ISINTEGER(&Item) ) {
		CComVariant	v(Item);
		v.ChangeType(VT_UI4);
		if( V_UI4(&v) >= m_listOfCS.size() )
			return i;
		i = m_listOfCS.begin();
		advance( i, V_I4(&v) );
	} else if( V_ISBSTR(&Item) ) {
		i = find_if( m_listOfCS.begin(), m_listOfCS.end(), matchDescription( V_BSTR(&Item) ) );
	}
	return i;
}
Ejemplo n.º 17
0
bool CImageNET::Init( const std::wstring& path )
{
    HRESULT hr;
    VARIANT value;

    m_path = path;

    hr = CoInitialize(0);

    hr = CoCreateInstance(CLSID_CorMetaDataDispenser, NULL, CLSCTX_INPROC_SERVER, IID_IMetaDataDispenserEx, (void**)&m_pMetaDisp);
    if(FAILED(hr))
    {
        m_pMetaDisp = nullptr;
        return false;
    }

    //
    // query needed interfaces
    //
    hr = m_pMetaDisp->OpenScope(m_path.c_str(), 0, IID_IMetaDataImport, (IUnknown**)&m_pMetaImport);
    if (hr == CLDB_E_BADUPDATEMODE)
    {
        V_VT(&value)  = VT_UI4;
        V_UI4(&value) = MDUpdateIncremental;

        if (FAILED(hr = m_pMetaDisp->SetOption(MetaDataSetUpdate, &value)))
            return false;

        hr = m_pMetaDisp->OpenScope(m_path.c_str(), 0, IID_IMetaDataImport, (IUnknown**)&m_pMetaImport);
    }

    if (FAILED(hr))
        return false;

    hr = m_pMetaImport->QueryInterface(IID_IMetaDataAssemblyImport, (void**) &m_pAssemblyImport);
    if (FAILED(hr))
        return false;

    return true;
}
Ejemplo n.º 18
0
/// <summary>
/// Initialize COM classes
/// </summary>
/// <param name="path">Image file path</param>
/// <returns>true on success</returns>
bool ImageNET::Init( const std::wstring& path )
{
    HRESULT hr;
    VARIANT value;

    _path = path;

    if (FAILED( CoInitialize( 0 ) ))
         return false;

    hr = CoCreateInstance( CLSID_CorMetaDataDispenser, NULL, CLSCTX_INPROC_SERVER, 
                           IID_IMetaDataDispenserEx, reinterpret_cast<void**>(&_pMetaDisp) );
    if (FAILED( hr ))
        return false;

    //
    // query required interfaces
    //
    hr = _pMetaDisp->OpenScope( _path.c_str(), 0, IID_IMetaDataImport, reinterpret_cast<IUnknown**>(&_pMetaImport) );
    if (hr == CLDB_E_BADUPDATEMODE)
    {
        V_VT(&value)  = VT_UI4;
        V_UI4(&value) = MDUpdateIncremental;

        if (FAILED( hr = _pMetaDisp->SetOption( MetaDataSetUpdate, &value ) ))
            return false;

        hr = _pMetaDisp->OpenScope( _path.c_str(), 0, IID_IMetaDataImport, reinterpret_cast<IUnknown**>(&_pMetaImport) );
    }

    if (FAILED( hr ))
        return false;

    hr = _pMetaImport->QueryInterface( IID_IMetaDataAssemblyImport, reinterpret_cast<void**>(&_pAssemblyImport) );
    if (FAILED( hr ))
        return false;

    return true;
}
Ejemplo n.º 19
0
HRESULT CAsmLink::Init(IMetaDataDispenserEx *pDispenser, IMetaDataError *pError)
{

    VARIANT v;
    HRESULT hr;
    ASSERT(!m_bInited && pDispenser != NULL);
    m_pDisp = pDispenser;
    m_pDisp->AddRef();

    memset(&v, 0, sizeof(v));
    V_VT(&v) = VT_EMPTY;
    if (SUCCEEDED(hr = m_pDisp->GetOption(MetaDataCheckDuplicatesFor, &v))) {
        V_UI4(&v) |= MDDupModuleRef | MDDupAssemblyRef | MDDupAssembly;
        hr = m_pDisp->SetOption(MetaDataCheckDuplicatesFor, &v);
    }

    if (pError != NULL) {
        m_pError = pError;
        m_pError->AddRef();
    } else
        m_pError = NULL;
    m_bInited = true;
    return hr;
}
Ejemplo n.º 20
0
HRESULT dhGetValueV(LPCWSTR szIdentifier, void * pResult, IDispatch * pDisp, LPCOLESTR szMember, va_list * marker)
{
	VARIANT vtResult;
	VARTYPE returnType;
	HRESULT hr;

	DH_ENTER(L"GetValueV");

	if (!pResult || !szIdentifier) return DH_EXIT(E_INVALIDARG, szMember);

	if (*szIdentifier == L'%') szIdentifier++;

	switch(*szIdentifier)
	{
		case L'd': returnType = VT_I4;       break;
		case L'u': returnType = VT_UI4;      break;
		case L'e': returnType = VT_R8;       break;
		case L'b': returnType = VT_BOOL;     break;
		case L'v': returnType = VT_EMPTY;    break;
		case L'B': returnType = VT_BSTR;     break;
		case L'S': returnType = VT_BSTR;     break;
		case L's': returnType = VT_BSTR;     break;
		case L'T': returnType = VT_BSTR;     break;
		case L'o': returnType = VT_DISPATCH; break;
		case L'O': returnType = VT_UNKNOWN;  break;
		case L't': returnType = VT_DATE;     break;
		case L'W': returnType = VT_DATE;     break;
		case L'f': returnType = VT_DATE;     break;
		case L'D': returnType = VT_DATE;     break;
#ifndef _WIN64
		case L'p': returnType = VT_I4;       break;
#else
		case L'p': returnType = VT_I8;       break;
#endif
		default:
			DEBUG_NOTIFY_INVALID_IDENTIFIER(*szIdentifier);
			return DH_EXIT(E_INVALIDARG, szMember);
	}

	hr = dhInvokeV(DISPATCH_PROPERTYGET|DISPATCH_METHOD, returnType, &vtResult, pDisp, szMember, marker);
	if (FAILED(hr)) return DH_EXIT(hr, szMember);

	switch(*szIdentifier)
	{
		case L'd':
			*((LONG *) pResult) = V_I4(&vtResult);
			break;

		case L'u':
			*((ULONG *) pResult) = V_UI4(&vtResult);
			break;

		case L'e':
			*((DOUBLE *) pResult) = V_R8(&vtResult);
			break;

		case L'b':
			*((BOOL *) pResult) = V_BOOL(&vtResult);
			break;

		case L'v':
			*((VARIANT *) pResult) = vtResult;
			break;

		case L'B':
			*((BSTR *) pResult) = V_BSTR(&vtResult);
			break;

		case L'S':
			*((LPWSTR *) pResult) = V_BSTR(&vtResult);
			break;

		case L's':
			hr = ConvertBStrToAnsiStr(V_BSTR(&vtResult), (LPSTR *) pResult);
			SysFreeString(V_BSTR(&vtResult));
			break;

		case L'T':
			if (dh_g_bIsUnicodeMode)
			{
				*((LPWSTR *) pResult) = V_BSTR(&vtResult);
			}
			else
			{
				hr = ConvertBStrToAnsiStr(V_BSTR(&vtResult), (LPSTR *) pResult);
				SysFreeString(V_BSTR(&vtResult));
			}
			break;

		case L'o':
			*((IDispatch **) pResult) = V_DISPATCH(&vtResult);
			if (V_DISPATCH(&vtResult) == NULL) hr = E_NOINTERFACE;
			break;

		case L'O':
			*((IUnknown **) pResult) = V_UNKNOWN(&vtResult);
			if (V_UNKNOWN(&vtResult) == NULL) hr = E_NOINTERFACE;
			break;

		case L't':
			hr = ConvertVariantTimeToTimeT(V_DATE(&vtResult), (time_t *) pResult);
			break;

		case L'W':
			hr = ConvertVariantTimeToSystemTime(V_DATE(&vtResult), (SYSTEMTIME *) pResult);
			break;

		case L'f':
			hr = ConvertVariantTimeToFileTime(V_DATE(&vtResult), (FILETIME *) pResult);
			break;

		case L'D':
			*((DATE *) pResult) = V_DATE(&vtResult);
			break;

		case L'p':
#ifndef _WIN64
			*((LPVOID *) pResult) = (LPVOID) V_I4(&vtResult);
#else
			*((LPVOID *) pResult) = (LPVOID) V_I8(&vtResult);
#endif
			break;
	}

	return DH_EXIT(hr, szMember);
}
Ejemplo n.º 21
0
HRESULT CAsmLink::SetAssemblyProps(mdAssembly AssemblyID, mdToken FileToken, AssemblyOptions Option, VARIANT Value)
{
    ASSERT(m_bInited && !m_bPreClosed && m_pAssem && !m_bManifestEmitted);
    ASSERT(AssemblyID == TokenFromRid(mdtAssembly, 1) || AssemblyID == AssemblyIsUBM);
    ASSERT((RidFromToken(FileToken) < m_pAssem->CountFiles() && TypeFromToken(FileToken) == mdtFile) ||
        (FileToken == AssemblyID));

    HRESULT hr = S_OK;
    if (Option >= optLastAssemOption || OptionCAs[Option].flag & 0x40)
        return E_INVALIDARG;
    if (AssemblyID == AssemblyIsUBM || (OptionCAs[Option].flag & 0x02)) {
        CFile *file = NULL;
        if (FileToken == AssemblyID)
            file = m_pAssem;
        else if (FAILED(hr = m_pAssem->GetFile(FileToken, &file)))
            return hr;

        ASSERT(file->GetEmitScope());
        IMetaDataEmit* pEmit = file->GetEmitScope();
        CComPtr<IMetaDataImport> pImport;
        mdToken tkAttrib = mdTokenNil, tkCtor;
        DWORD cbValue = 0, cbSig = 4;
        BYTE pbValue[2048];
        PBYTE pBlob = pbValue;
        COR_SIGNATURE newSig[9];
        LPCWSTR wszStr = NULL;
        ULONG wLen = 0;

        if (FAILED(hr = pEmit->QueryInterface(IID_IMetaDataImport, (void**)&pImport)))
            return hr;

        // Find or Create the TypeRef (This always scopes it to MSCORLIB)
        if (FAILED(hr = file->GetTypeRef(OptionCAs[Option].name, &tkAttrib)))
            return hr;

        // Make the Blob
        newSig[0] = (IMAGE_CEE_CS_CALLCONV_DEFAULT | IMAGE_CEE_CS_CALLCONV_HASTHIS);
        newSig[1] = 1; // One parameter
        newSig[2] = ELEMENT_TYPE_VOID;
        *(WORD*)pBlob = VAL16(1); // This is aligned
        pBlob += sizeof(WORD);

        if (V_VT(&Value) != OptionCAs[Option].vt)
            return E_INVALIDARG;
        switch(OptionCAs[Option].vt) {
        case VT_BOOL:
            *pBlob++ = (V_BOOL(&Value) == VARIANT_TRUE);
            newSig[3] = ELEMENT_TYPE_BOOLEAN;
            break;
        case VT_UI4:
            SET_UNALIGNED_VAL32(pBlob, V_UI4(&Value));
            pBlob += sizeof(ULONG);
            newSig[3] = ELEMENT_TYPE_U4;
            break;
        case VT_BSTR:
            if (Option == optAssemOS) {
                LPWSTR end = NULL;
                mdToken tkPlatform = mdTokenNil;
                newSig[1] = 2; // Two parameters
                newSig[3] = ELEMENT_TYPE_VALUETYPE;

                // Make the TypeRef
                if (FAILED(hr = file->GetTypeRef( PLATFORMID_NAME, &tkPlatform)))
                     break;

                cbSig = 5 + CorSigCompressToken(tkPlatform, newSig + 4);
                newSig[cbSig - 1] = ELEMENT_TYPE_STRING;
                SET_UNALIGNED_VAL32(pBlob, wcstoul(V_BSTR(&Value), &end, 0)); // Parse Hex, Octal, and Decimal
                pBlob += sizeof(ULONG);
                if (*end == L'.') {
                    wszStr = end++;
                    wLen = SysStringLen(V_BSTR(&Value)) - (UINT)(V_BSTR(&Value) - end);
                    goto ADDSTRING;
                } else {
                    hr = file->ReportError(ERR_InvalidOSString);
                    return hr;
                }
            } else {
                newSig[3] = ELEMENT_TYPE_STRING;
                wLen = SysStringLen(V_BSTR(&Value));
                wszStr = V_BSTR(&Value);
ADDSTRING:
                if (wLen == 0) {
                    // Too small for unilib
                    *pBlob++ = 0xFF;
                } else if (wLen & 0x80000000) {
                    // Too big!
                    return ReportOptionError(file, Option, E_INVALIDARG);
                } else if ((OptionCAs[Option].flag & 0x10) && wLen > MAX_PATH) {
                    // Too big!
                    return ReportOptionError(file, Option, HRESULT_FROM_WIN32(ERROR_BUFFER_OVERFLOW)); // File name too long
                } else {
                    CHAR pUTF8[2048];
                    int iLen = wLen;
    
                    wLen = (UINT)UnicodeToUTF8(wszStr, &iLen, pUTF8, lengthof(pUTF8));

                    iLen = (int)CorSigCompressData( wLen, pBlob);
                    pBlob += iLen;
                    if (wLen > (UINT)(pbValue + lengthof(pbValue) - pBlob)) {
                        // Too big!
                        return ReportOptionError(file, Option, HRESULT_FROM_WIN32(ERROR_BUFFER_OVERFLOW));
                    }
                    memcpy(pBlob, pUTF8, wLen);
                    pBlob += wLen;
                }
            }
            break;
        default:
            VSFAIL("Unknown Option Type!");
            newSig[3] = ELEMENT_TYPE_OBJECT;
            break;
        }
        hr = pImport->FindMemberRef(tkAttrib, L".ctor", newSig, cbSig, &tkCtor);
        if ((hr == CLDB_E_RECORD_NOTFOUND && FAILED(hr = pEmit->DefineMemberRef(tkAttrib, L".ctor", newSig, 4, &tkCtor))) ||
            FAILED(hr))
            return hr;
        cbValue = (DWORD)(pBlob - pbValue);

        // Emit the CA
        // This will also set the option if appropriate
        hr = EmitAssemblyCustomAttribute( AssemblyID, FileToken, tkCtor, pbValue, cbValue, 
            (OptionCAs[Option].flag & 0x08) ? TRUE : FALSE,
            (OptionCAs[Option].flag & 0x04) ? TRUE : FALSE);
    } else {
        // An assembly level custom attribute
        hr = m_pAssem->SetOption(Option, &Value);
    }
    return hr;
}
Ejemplo n.º 22
0
bool
variant_as_string( DEBUGHELPER *pH, const VARIANT &var, std::string *ret  )
{
	if (var.vt & VT_VECTOR) return false;
	if (var.vt & VT_RESERVED) return false;
	if (var.vt & VT_ARRAY)
		return safearray_as_string( pH, reinterpret_cast<DWORDLONG>(var.parray), ret);

	if (var.vt & VT_BYREF)
	{
		// Construct a fake variant with the byref-value in it.
		VARTYPE vt = var.vt & ~VT_BYREF;
		long size = vartype_len(vt);
		VARIANT var2;
		var2.vt = vt;
		long source=reinterpret_cast<long>(var.byref);
		void *dest;
		if( vt == VT_VARIANT)
			dest = &var2;
		else
		{
			var2.vt=vt;
			dest = &(var2.bVal);
		}
		if(!ReadMem(pH,source, size, dest)) return false;

		std::string retval;
		if( ! variant_as_string( pH, var2, &retval)) return false;

		retval += "]";
		*ret = "[" + retval;
		return true;
	}
	
	std::ostringstream os;
	switch (var.vt & VT_TYPEMASK )
	{
		case VT_I2: os << V_I2(&var); break;
		case VT_I4: os << V_I4(&var); break;
		//case VT_I8: os << V_I8(&var); break;
		case VT_R4: os << V_R4(&var); break;
		case VT_R8: os << V_R8(&var); break;

		case VT_UNKNOWN:
		case VT_DISPATCH: os <<  "0x" << std::hex << (long )V_DISPATCH(&var); break;
		case VT_BOOL: os << (V_BOOL(&var)==VARIANT_FALSE?"False":"True"); break;
		case VT_I1: os << "'" << V_I1(&var) << "'"  ; break;
		case VT_UI1: os << "'" << V_UI1(&var) << "'" ; break;
		case VT_UI2: os << V_UI2(&var); break;
		case VT_UI4: os << V_UI4(&var); break;
		case VT_INT: os << V_INT(&var); break;
		case VT_UINT: os << V_UINT(&var); break;
		case VT_ERROR: os << "error"; break;

		case VT_CY: os << (((double)(V_CY(&var).int64))/10000.); break;
		case VT_DATE: return date_as_string(V_DATE(&var), ret); break;

		case VT_BSTR:
		{

			long pBSTR = reinterpret_cast<long>( V_BSTR(&var) );
//			if (!ReadMem(pH, reinterpret_cast<DWORDLONG>( V_BSTR(&var) ), &pBSTR)) return false;

			std::string ret;
			if (!bstr_as_string( pH, pBSTR , &ret )) return false;
			os << ret;
		}break;
		case VT_EMPTY: os << '@'; break;
		case VT_NULL: os << "null"; break;
		break;
		default:
			return false;
	}

	*ret =  os.str();
	return true;
	
}
void CPageEvents::OnOK() 
{
  // Save any changes made to the currently-selected node's attributes
  UpdateNodeFromItem(m_lParamSelected);

  // Inspect the <Event> nodes of the document
  if (NULL != m_spXMLDoc)
  {
    // Get all of the <Event> nodes in the document
    IXMLDOMNodeListPtr spNodeList;
    VERIFY(SUCCEEDED(m_spXMLDoc->getElementsByTagName(m_bstrEvent,
      &spNodeList)));

    // Process each node
    IXMLDOMNodePtr spNode;
    do  
    {
      // Get the next node of the child list
      VERIFY(SUCCEEDED(spNodeList->nextNode(&spNode)));
      if (NULL != spNode)
      {
        // Query for the IXMLDOMElement interface
        IXMLDOMElementPtr spElement(spNode);
        ASSERT(NULL != spElement);

        // Get the event id attribute
        CComVariant varEventID;
        spElement->getAttribute(m_bstrID, &varEventID);
        VERIFY(SUCCEEDED(varEventID.ChangeType(VT_I4)));
        AGCEventID idEventBegin = (AGCEventID)(V_UI4(&varEventID));
        AGCEventID idEventEnd = (AGCEventID)(idEventBegin + 1);

        // Get the LogAsNTEvent attribute
        IXMLDOMAttributePtr spAttrNT;
        if (S_OK == spElement->getAttributeNode(m_bstrLogAsNTEvent, &spAttrNT))
        {
          CComVariant varLog2NT;
          spAttrNT->get_value(&varLog2NT);
          VERIFY(SUCCEEDED(varLog2NT.ChangeType(VT_BOOL)));

          // Add this event id to the range, if it should be logged
          if (V_BOOL(&varLog2NT))
            m_spRangesNT->AddByValues(idEventBegin, idEventEnd);
        }

        // Get the LogAsDBEvent attribute
        IXMLDOMAttributePtr spAttrDB;
        if (S_OK == spElement->getAttributeNode(m_bstrLogAsDBEvent, &spAttrDB))
        {
          CComVariant varLog2DB;
          spAttrDB->get_value(&varLog2DB);
          VERIFY(SUCCEEDED(varLog2DB.ChangeType(VT_BOOL)));

          // Add this event id to the range, if it should be logged
          if (V_BOOL(&varLog2DB))
            m_spRangesDB->AddByValues(idEventBegin, idEventEnd);
        }
      }
    } while (NULL != spNode);

    // Set the enabled ranges of the event logger object
    VERIFY(SUCCEEDED(m_spEventLogger->put_EnabledNTEvents(m_spRangesNT)));
    VERIFY(SUCCEEDED(m_spEventLogger->put_EnabledDBEvents(m_spRangesDB)));
  }

  // Perform default processing
  CPropertyPage::OnOK();
}
HRESULT CPageEvents::UpdateItemFromNode(LPARAM lNode)
{
  USES_CONVERSION;

  // Typecast the tree item's param as an XML element pointer
  IXMLDOMElement* pElement = reinterpret_cast<IXMLDOMElement*>(lNode);
  if (!pElement)
    return S_FALSE;

  // Use to enable/disable the check boxes
  bool bEnableLog2NT = false;
  bool bEnableLog2DB = false;

  // Determine if the node is a group element or an event
  CComBSTR bstrTagName;
  VERIFY(SUCCEEDED(pElement->get_tagName(&bstrTagName)));
  bool bIsEvent = 0 == wcscmp(bstrTagName, m_bstrEvent);
  bool bIsGroup = !bIsEvent && 0 == wcscmp(bstrTagName, m_bstrEventGroup);
  ASSERT(bIsEvent || bIsGroup);
  if (bIsEvent)
  {
    // Get the Severity attribute
    CComVariant varSeverity;
    pElement->getAttribute(m_bstrSeverity, &varSeverity);
    VERIFY(SUCCEEDED(varSeverity.ChangeType(VT_BSTR)));
    SetDlgItemText(IDC_EVENT_TYPE, TypeFromSeverity(V_BSTR(&varSeverity)));

    // Get the event id attribute
    CComVariant varEventID;
    pElement->getAttribute(m_bstrID, &varEventID);
    VERIFY(SUCCEEDED(varEventID.ChangeType(VT_I4)));
    SetDlgItemInt(IDC_EVENT_ID, V_I4(&varEventID));

    // Get the CanChangeLogAsNTEvent attribute
    IXMLDOMAttributePtr spAttrNT;
    if (S_OK == pElement->getAttributeNode(m_bstrCanChangeLogAsNTEvent, &spAttrNT))
    {
      CComVariant varCanChange;
      spAttrNT->get_value(&varCanChange);
      VERIFY(SUCCEEDED(varCanChange.ChangeType(VT_BOOL)));
      bEnableLog2NT = !!V_BOOL(&varCanChange);
    }
    else
    {
      // When not specified, the default is true
      bEnableLog2NT = true;
    }

    // Get the LogAsNTEvent attribute
    CComVariant varLog2NT;
    pElement->getAttribute(m_bstrLogAsNTEvent, &varLog2NT);
    VERIFY(SUCCEEDED(varLog2NT.ChangeType(VT_BOOL)));
    CheckDlgButton(IDC_LOG2NT, V_BOOL(&varLog2NT));

    // Get the CanChangeLogAsDBEvent attribute
    IXMLDOMAttributePtr spAttrDB;
    if (S_OK == pElement->getAttributeNode(m_bstrCanChangeLogAsDBEvent, &spAttrDB))
    {
      CComVariant varCanChange;
      spAttrDB->get_value(&varCanChange);
      VERIFY(SUCCEEDED(varCanChange.ChangeType(VT_BOOL)));
      bEnableLog2DB = !!V_BOOL(&varCanChange);
    }
    else
    {
      // When not specified, the default is true
      bEnableLog2DB = true;
    }

    // Get the LogAsDBEvent attribute
    CComVariant varLog2DB;
    pElement->getAttribute(m_bstrLogAsDBEvent, &varLog2DB);
    VERIFY(SUCCEEDED(varLog2DB.ChangeType(VT_BOOL)));
    CheckDlgButton(IDC_LOG2DB, V_BOOL(&varLog2DB));
  }
  else
  {
    // Always show the type as "Group"
    CString strGroup;
    strGroup.LoadString(IDS_TYPE_GROUP);
    SetDlgItemText(IDC_EVENT_TYPE, strGroup);

    // Get the group LowerBound attribute
    CComVariant varLowerBound;
    pElement->getAttribute(m_bstrLowerBound, &varLowerBound);
    VERIFY(SUCCEEDED(varLowerBound.ChangeType(VT_UI4)));

    // Get the group UpperBound attribute
    CComVariant varUpperBound;
    pElement->getAttribute(m_bstrUpperBound, &varUpperBound);
    VERIFY(SUCCEEDED(varUpperBound.ChangeType(VT_UI4)));

    // Format the group's range into a string
    TCHAR szID[_MAX_PATH];
    wsprintf(szID, TEXT("%u - %u"), V_UI4(&varLowerBound),
      V_UI4(&varUpperBound));
    SetDlgItemText(IDC_EVENT_ID, szID);

    // TODO: Work-out how to best support indeterminate checkbox state
    CheckDlgButton(IDC_LOG2NT, false);
    CheckDlgButton(IDC_LOG2DB, false);
  }

  // Get the event/group Description attribute
  CComVariant varDescription;
  pElement->getAttribute(m_bstrDescription, &varDescription);
  VERIFY(SUCCEEDED(varDescription.ChangeType(VT_BSTR)));
  SetDlgItemText(IDC_DESCRIPTION, OLE2CT(V_BSTR(&varDescription)));

  // Enable/disable checkboxes
  GetDlgItem(IDC_LOG2NT)->EnableWindow(bEnableLog2NT);
  GetDlgItem(IDC_LOG2DB)->EnableWindow(bEnableLog2DB);

  // Uncheck checkboxes that are disabled
  if (!bEnableLog2NT)
    CheckDlgButton(IDC_LOG2NT, false);
  if (!bEnableLog2DB)
    CheckDlgButton(IDC_LOG2DB, false);

  // Indicate success
  return S_OK;
}
Ejemplo n.º 25
0
static HRESULT DXDiag_InitDXDiagDirectShowFiltersContainer(IDxDiagContainer* pSubCont) {
    HRESULT hr = S_OK;
    static const WCHAR szName[] = {'s','z','N','a','m','e',0};
    static const WCHAR szCatName[] = {'s','z','C','a','t','N','a','m','e',0};
    static const WCHAR szClsidCat[] = {'s','z','C','l','s','i','d','C','a','t',0};
    static const WCHAR szClsidFilter[] = {'s','z','C','l','s','i','d','F','i','l','t','e','r',0};
    static const WCHAR dwInputs[] = {'d','w','I','n','p','u','t','s',0};
    static const WCHAR dwOutputs[] = {'d','w','O','u','t','p','u','t','s',0};
    static const WCHAR dwMerit[] = {'d','w','M','e','r','i','t',0};
    /*
    static const WCHAR szFileName[] = {'s','z','F','i','l','e','N','a','m','e',0};
    static const WCHAR szFileVersion[] = {'s','z','F','i','l','e','V','e','r','s','i','o','n',0};
    */
    VARIANT v;

    static const WCHAR wszClsidName[] = {'C','L','S','I','D',0};
    static const WCHAR wszFriendlyName[] = {'F','r','i','e','n','d','l','y','N','a','m','e',0};
    static const WCHAR wszFilterDataName[] = {'F','i','l','t','e','r','D','a','t','a',0};
    /*static const WCHAR wszMeritName[] = {'M','e','r','i','t',0};*/

    ICreateDevEnum* pCreateDevEnum = NULL;
    IEnumMoniker* pEmCat = NULL;
    IMoniker* pMCat = NULL;
    /** */
    hr = CoCreateInstance(&CLSID_SystemDeviceEnum,
                          NULL,
                          CLSCTX_INPROC_SERVER,
                          &IID_ICreateDevEnum,
                          (void**) &pCreateDevEnum);
    if (FAILED(hr)) return hr;

    hr = ICreateDevEnum_CreateClassEnumerator(pCreateDevEnum, &CLSID_ActiveMovieCategories, &pEmCat, 0);
    if (FAILED(hr)) goto out_show_filters;

    VariantInit(&v);

    while (S_OK == IEnumMoniker_Next(pEmCat, 1, &pMCat, NULL)) {
        IPropertyBag* pPropBag = NULL;
        CLSID clsidCat;
        hr = IMoniker_BindToStorage(pMCat, NULL, NULL, &IID_IPropertyBag, (void**) &pPropBag);
        if (SUCCEEDED(hr)) {
            WCHAR* wszCatName = NULL;
            WCHAR* wszCatClsid = NULL;

            hr = IPropertyBag_Read(pPropBag, wszFriendlyName, &v, 0);
            wszCatName = SysAllocString(V_BSTR(&v));
            VariantClear(&v);

            hr = IPropertyBag_Read(pPropBag, wszClsidName, &v, 0);
            wszCatClsid = SysAllocString(V_BSTR(&v));
            hr = CLSIDFromString(V_UNION(&v, bstrVal), &clsidCat);
            VariantClear(&v);

            /*
            hr = IPropertyBag_Read(pPropBag, wszMeritName, &v, 0);
            hr = IDxDiagContainerImpl_AddProp(pSubCont, dwMerit, &v);
            VariantClear(&v);
            */

            if (SUCCEEDED(hr)) {
                IEnumMoniker* pEnum = NULL;
                IMoniker* pMoniker = NULL;
                hr = ICreateDevEnum_CreateClassEnumerator(pCreateDevEnum, &clsidCat, &pEnum, 0);
                FIXME("\tClassEnumerator for clsid(%s) pEnum(%p)\n", debugstr_guid(&clsidCat), pEnum);
                if (FAILED(hr) || pEnum == NULL) {
                    goto class_enum_failed;
                }
                while (NULL != pEnum && S_OK == IEnumMoniker_Next(pEnum, 1, &pMoniker, NULL)) {
                    IPropertyBag* pPropFilterBag = NULL;
                    FIXME("\tIEnumMoniker_Next(%p, 1, %p)\n", pEnum, pMoniker);
                    hr = IMoniker_BindToStorage(pMoniker, NULL, NULL, &IID_IPropertyBag, (void**) &pPropFilterBag);
                    if (SUCCEEDED(hr)) {
                        LPBYTE pData = NULL;
                        LPBYTE pCurrent = NULL;
                        struct REG_RF* prrf = NULL;
                        VARIANT v_data;
                        DWORD it;
                        DWORD dwNOutputs = 0;
                        DWORD dwNInputs = 0;

                        V_VT(&v) = VT_BSTR;
                        V_BSTR(&v) = SysAllocString(wszCatName);
                        hr = IDxDiagContainerImpl_AddProp(pSubCont, szCatName, &v);
                        VariantClear(&v);

                        V_VT(&v) = VT_BSTR;
                        V_BSTR(&v) = SysAllocString(wszCatClsid);
                        hr = IDxDiagContainerImpl_AddProp(pSubCont, szClsidCat, &v);
                        VariantClear(&v);

                        hr = IPropertyBag_Read(pPropFilterBag, wszFriendlyName, &v, 0);
                        hr = IDxDiagContainerImpl_AddProp(pSubCont, szName, &v);
                        FIXME("\tName:%s\n", debugstr_w(V_BSTR(&v)));
                        VariantClear(&v);

                        hr = IPropertyBag_Read(pPropFilterBag, wszClsidName, &v, 0);
                        FIXME("\tClsid:%s\n", debugstr_w(V_BSTR(&v)));
                        hr = IDxDiagContainerImpl_AddProp(pSubCont, szClsidFilter, &v);
                        VariantClear(&v);

                        hr = IPropertyBag_Read(pPropFilterBag, wszFilterDataName, &v, NULL);
                        hr = SafeArrayAccessData(V_UNION(&v, parray), (LPVOID*) &pData);
                        prrf = (struct REG_RF*) pData;
                        pCurrent = pData;

                        VariantInit(&v_data);
                        V_VT(&v_data) = VT_UI4;
                        V_UI4(&v_data) = prrf->dwVersion;
                        hr = IDxDiagContainerImpl_AddProp(pSubCont, szName, &v_data);
                        VariantClear(&v_data);
                        V_VT(&v_data) = VT_UI4;
                        V_UI4(&v_data) = prrf->dwMerit;
                        hr = IDxDiagContainerImpl_AddProp(pSubCont, dwMerit, &v_data);
                        VariantClear(&v_data);

                        pCurrent += sizeof(struct REG_RF);
                        for (it = 0; it < prrf->dwPins; ++it) {
                            struct REG_RFP* prrfp = (struct REG_RFP*) pCurrent;
                            UINT j;

                            if (prrfp->dwFlags & REG_PINFLAG_B_OUTPUT) ++dwNOutputs;
                            else ++dwNInputs;

                            pCurrent += sizeof(struct REG_RFP);
                            if (prrfp->bCategory) {
                                pCurrent += sizeof(DWORD);
                            }
                            for (j = 0; j < prrfp->dwMediaTypes; ++j) {
                                struct REG_TYPE* prt = (struct REG_TYPE *)pCurrent;
                                pCurrent += sizeof(*prt);
                            }
                            for (j = 0; j < prrfp->dwMediums; ++j) {
                                DWORD dwOffset = *(DWORD*) pCurrent;
                                pCurrent += sizeof(dwOffset);
                            }
                        }

                        V_VT(&v_data) = VT_UI4;
                        V_UI4(&v_data) = dwNInputs;
                        hr = IDxDiagContainerImpl_AddProp(pSubCont, dwInputs, &v_data);
                        VariantClear(&v_data);
                        V_VT(&v_data) = VT_UI4;
                        V_UI4(&v_data) = dwNOutputs;
                        hr = IDxDiagContainerImpl_AddProp(pSubCont, dwOutputs, &v_data);
                        VariantClear(&v_data);

                        SafeArrayUnaccessData(V_UNION(&v, parray));
                        VariantClear(&v);
                    }
                    IPropertyBag_Release(pPropFilterBag);
                    pPropFilterBag = NULL;
                }
                IEnumMoniker_Release(pEnum);
                pEnum = NULL;
            }
class_enum_failed:
            SysFreeString(wszCatName);
            SysFreeString(wszCatClsid);
            IPropertyBag_Release(pPropBag);
            pPropBag = NULL;
        }
        IEnumMoniker_Release(pMCat);
        pMCat = NULL;
    }

out_show_filters:
    if (NULL != pEmCat) {
        IEnumMoniker_Release(pEmCat);
        pEmCat = NULL;
    }
    if (NULL != pCreateDevEnum) {
        ICreateDevEnum_Release(pCreateDevEnum);
        pCreateDevEnum = NULL;
    }
    return hr;
}
Ejemplo n.º 26
0
PHP_COM_DOTNET_API int php_com_zval_from_variant(zval *z, VARIANT *v, int codepage TSRMLS_DC)
{
	OLECHAR *olestring = NULL;
	int ret = SUCCESS;

	switch (V_VT(v)) {
		case VT_EMPTY:
		case VT_NULL:
		case VT_VOID:
			ZVAL_NULL(z);
			break;
		case VT_UI1:
			ZVAL_LONG(z, (long)V_UI1(v));
			break;
		case VT_I1:
			ZVAL_LONG(z, (long)V_I1(v));
			break;
		case VT_UI2:
			ZVAL_LONG(z, (long)V_UI2(v));
			break;
		case VT_I2:
			ZVAL_LONG(z, (long)V_I2(v));
			break;
		case VT_UI4:  /* TODO: promote to double if large? */
			ZVAL_LONG(z, (long)V_UI4(v));
			break;
		case VT_I4:
			ZVAL_LONG(z, (long)V_I4(v));
			break;
		case VT_INT:
			ZVAL_LONG(z, V_INT(v));
			break;
		case VT_UINT: /* TODO: promote to double if large? */
			ZVAL_LONG(z, (long)V_UINT(v));
			break;
		case VT_R4:
			ZVAL_DOUBLE(z, (double)V_R4(v));
			break;
		case VT_R8:
			ZVAL_DOUBLE(z, V_R8(v));
			break;
		case VT_BOOL:
			ZVAL_BOOL(z, V_BOOL(v) ? 1 : 0);
			break;
		case VT_BSTR:
			olestring = V_BSTR(v);
			if (olestring) {
				Z_TYPE_P(z) = IS_STRING;
				Z_STRVAL_P(z) = php_com_olestring_to_string(olestring,
					&Z_STRLEN_P(z), codepage TSRMLS_CC);
				olestring = NULL;
			}
			break;
		case VT_UNKNOWN:
			if (V_UNKNOWN(v) != NULL) {
				IDispatch *disp;

				if (SUCCEEDED(IUnknown_QueryInterface(V_UNKNOWN(v), &IID_IDispatch, &disp))) {
					php_com_wrap_dispatch(z, disp, codepage TSRMLS_CC);
					IDispatch_Release(disp);
				} else {
					ret = FAILURE;
				}
			}
			break;

		case VT_DISPATCH:
			if (V_DISPATCH(v) != NULL) {
				php_com_wrap_dispatch(z, V_DISPATCH(v), codepage TSRMLS_CC);
			}
			break;

		case VT_VARIANT:
			/* points to another variant */
			return php_com_zval_from_variant(z, V_VARIANTREF(v), codepage TSRMLS_CC);
			
		default:
			php_com_wrap_variant(z, v, codepage TSRMLS_CC);
	}

	if (olestring) {
		efree(olestring);
	}

	if (ret == FAILURE) {
		php_error_docref(NULL TSRMLS_CC, E_WARNING, "variant->zval: conversion from 0x%x ret=%d", V_VT(v), ret);
	}

	return ret;
}
Ejemplo n.º 27
0
static void
ole_set_byref(VARIANT *realvar, VARIANT *var,  VARTYPE vt)
{
    V_VT(var) = vt;
    if (vt == (VT_VARIANT|VT_BYREF)) {
        V_VARIANTREF(var) = realvar;
    } else {
        if (V_VT(realvar) != (vt & ~VT_BYREF)) {
            rb_raise(eWIN32OLERuntimeError, "variant type mismatch");
        }
        switch(vt & ~VT_BYREF) {
        case VT_I1:
            V_I1REF(var) = &V_I1(realvar);
            break;
        case VT_UI1:
            V_UI1REF(var) = &V_UI1(realvar);
            break;
        case VT_I2:
            V_I2REF(var) = &V_I2(realvar);
            break;
        case VT_UI2:
            V_UI2REF(var) = &V_UI2(realvar);
            break;
        case VT_I4:
            V_I4REF(var) = &V_I4(realvar);
            break;
        case VT_UI4:
            V_UI4REF(var) = &V_UI4(realvar);
            break;
        case VT_R4:
            V_R4REF(var) = &V_R4(realvar);
            break;
        case VT_R8:
            V_R8REF(var) = &V_R8(realvar);
            break;

#if (_MSC_VER >= 1300) || defined(__CYGWIN__) || defined(__MINGW32__)
#ifdef V_I8REF
        case VT_I8:
            V_I8REF(var) = &V_I8(realvar);
            break;
#endif
#ifdef V_UI8REF
        case VT_UI8:
            V_UI8REF(var) = &V_UI8(realvar);
            break;
#endif
#endif
        case VT_INT:
            V_INTREF(var) = &V_INT(realvar);
            break;

        case VT_UINT:
            V_UINTREF(var) = &V_UINT(realvar);
            break;

        case VT_CY:
            V_CYREF(var) = &V_CY(realvar);
            break;
        case VT_DATE:
            V_DATEREF(var) = &V_DATE(realvar);
            break;
        case VT_BSTR:
            V_BSTRREF(var) = &V_BSTR(realvar);
            break;
        case VT_DISPATCH:
            V_DISPATCHREF(var) = &V_DISPATCH(realvar);
            break;
        case VT_ERROR:
            V_ERRORREF(var) = &V_ERROR(realvar);
            break;
        case VT_BOOL:
            V_BOOLREF(var) = &V_BOOL(realvar);
            break;
        case VT_UNKNOWN:
            V_UNKNOWNREF(var) = &V_UNKNOWN(realvar);
            break;
        case VT_ARRAY:
            V_ARRAYREF(var) = &V_ARRAY(realvar);
            break;
        default:
            rb_raise(eWIN32OLERuntimeError, "unknown type specified(setting BYREF):%d", vt);
            break;
        }
    }
}
Ejemplo n.º 28
0
void EventProxy::convertJavaVariant(VARIANT *java, VARIANT *com) {

	  switch (com->vt)
	  {	  
		case VT_DISPATCH:
		{
			switch (java->vt)
			{
				case VT_DISPATCH:
				{
					V_DISPATCH(com) = V_DISPATCH(java);
					break;
				}

				case VT_DISPATCH | VT_BYREF:
				{
					V_DISPATCH(com) = *V_DISPATCHREF(java);
					break;
				}
			}
			break;
		}

		case VT_DISPATCH | VT_BYREF:
		{
			switch (java->vt)
			{
				case VT_DISPATCH:
				{
					*V_DISPATCHREF(com) = V_DISPATCH(java);
					break;
				}

				case VT_DISPATCH | VT_BYREF:
				{
					*V_DISPATCHREF(com) = *V_DISPATCHREF(java);
					break;
				}
			}
			break;
		}

		case VT_BOOL:
		{
			switch (java->vt)
			{
				case VT_BOOL:
				{
					V_BOOL(com) = V_BOOL(java);
					break;
				}

				case VT_BOOL | VT_BYREF:
				{
					V_BOOL(com) = *V_BOOLREF(java);
					break;
				}
			}
			break;
		}

		case VT_BOOL | VT_BYREF:
		{
			switch (java->vt)
			{
				case VT_BOOL:
				{
					*V_BOOLREF(com) = V_BOOL(java);
					break;
				}

				case VT_BOOL | VT_BYREF:
				{
					*V_BOOLREF(com) = *V_BOOLREF(java);
					break;
				}
			}
			break;
		}

		case VT_UI1:
		{
			switch (java->vt)
			{
				case VT_UI1:
				{
					V_UI1(com) = V_UI1(java);
					break;
				}

				case VT_UI1 | VT_BYREF:
				{
					V_UI1(com) = *V_UI1REF(java);
					break;
				}
			}
			break;
		}

		case VT_UI1 | VT_BYREF:
		{
			switch (java->vt)
			{
				case VT_UI1:
				{
					*V_UI1REF(com) = V_UI1(java);
					break;
				}

				case VT_UI1 | VT_BYREF:
				{
					*V_UI1REF(com) = *V_UI1REF(java);
					break;
				}
			}
			break;
		}


		case VT_I2:
		{
			switch (java->vt)
			{
				case VT_I2:
				{
					V_I2(com) = V_I2(java);
					break;
				}

				case VT_I2 | VT_BYREF:
				{
					V_I2(com) = *V_I2REF(java);
					break;
				}
			}
			break;
		}

		case VT_I2 | VT_BYREF:
		{
			switch (java->vt)
			{
				case VT_I2:
				{
					*V_I2REF(com) = V_I2(java);
					break;
				}

				case VT_I2 | VT_BYREF:
				{
					*V_I2REF(com) = *V_I2REF(java);
					break;
				}
			}
			break;
		}

		case VT_I4:
		{
			switch (java->vt)
			{
				case VT_I4:
				{
					V_I4(com) = V_I4(java);
					break;
				}

				case VT_I4 | VT_BYREF:
				{
					V_I4(com) = *V_I4REF(java);
					break;
				}
			}
			break;
		}

		case VT_I4 | VT_BYREF:
		{
			switch (java->vt)
			{
				case VT_I4:
				{
					*V_I4REF(com) = V_I4(java);
					break;
				}

				case VT_I4 | VT_BYREF:
				{
					*V_I4REF(com) = *V_I4REF(java);
					break;
				}
			}
			break;
		}

		case VT_R4:
		{
			switch (java->vt)
			{
				case VT_R4:
				{
					V_R4(com) = V_R4(java);
					break;
				}

				case VT_R4 | VT_BYREF:
				{
					V_R4(com) = *V_R4REF(java);
					break;
				}
			}
			break;
		}

		case VT_R4 | VT_BYREF:
		{
			switch (java->vt)
			{
				case VT_R4:
				{
					*V_R4REF(com) = V_R4(java);
					break;
				}

				case VT_R4 | VT_BYREF:
				{
					*V_R4REF(com) = *V_R4REF(java);
					break;
				}
			}
			break;
		}

		case VT_R8:
		{
			switch (java->vt)
			{
				case VT_R8:
				{
					V_R8(com) = V_R8(java);
					break;
				}

				case VT_R8 | VT_BYREF:
				{
					V_R8(com) = *V_R8REF(java);
					break;
				}
			}
			break;
		}

		case VT_R8 | VT_BYREF:
		{
			switch (java->vt)
			{
				case VT_R8:
				{
					*V_R8REF(com) = V_R8(java);
					break;
				}

				case VT_R8 | VT_BYREF:
				{
					*V_R8REF(com) = *V_R8REF(java);
					break;
				}
			}
			break;
		}

				case VT_I1:
		{
			switch (java->vt)
			{
				case VT_I1:
				{
					V_I1(com) = V_I1(java);
					break;
				}

				case VT_I1 | VT_BYREF:
				{
					V_I1(com) = *V_I1REF(java);
					break;
				}
			}
			break;
		}

		case VT_I1 | VT_BYREF:
		{
			switch (java->vt)
			{
				case VT_I1:
				{
					*V_I1REF(com) = V_I1(java);
					break;
				}

				case VT_I1 | VT_BYREF:
				{
					*V_I1REF(com) = *V_I1REF(java);
					break;
				}
			}
			break;
		}

				case VT_UI2:
		{
			switch (java->vt)
			{
				case VT_UI2:
				{
					V_UI2(com) = V_UI2(java);
					break;
				}

				case VT_UI2 | VT_BYREF:
				{
					V_UI2(com) = *V_UI2REF(java);
					break;
				}
			}
			break;
		}

		case VT_UI2 | VT_BYREF:
		{
			switch (java->vt)
			{
				case VT_UI2:
				{
					*V_UI2REF(com) = V_UI2(java);
					break;
				}

				case VT_UI2 | VT_BYREF:
				{
					*V_UI2REF(com) = *V_UI2REF(java);
					break;
				}
			}
			break;
		}

				case VT_UI4:
		{
			switch (java->vt)
			{
				case VT_UI4:
				{
					V_UI4(com) = V_UI4(java);
					break;
				}

				case VT_UI4 | VT_BYREF:
				{
					V_UI4(com) = *V_UI4REF(java);
					break;
				}
			}
			break;
		}

		case VT_UI4 | VT_BYREF:
		{
			switch (java->vt)
			{
				case VT_UI4:
				{
					*V_UI4REF(com) = V_UI4(java);
					break;
				}

				case VT_UI4 | VT_BYREF:
				{
					*V_UI4REF(com) = *V_UI4REF(java);
					break;
				}
			}
			break;
		}

				case VT_INT:
		{
			switch (java->vt)
			{
				case VT_INT:
				{
					V_INT(com) = V_INT(java);
					break;
				}

				case VT_INT | VT_BYREF:
				{
					V_INT(com) = *V_INTREF(java);
					break;
				}
			}
			break;
		}

		case VT_INT | VT_BYREF:
		{
			switch (java->vt)
			{
				case VT_INT:
				{
					*V_INTREF(com) = V_INT(java);
					break;
				}

				case VT_INT | VT_BYREF:
				{
					*V_INTREF(com) = *V_INTREF(java);
					break;
				}
			}
			break;
		}

				case VT_UINT:
		{
			switch (java->vt)
			{
				case VT_UINT:
				{
					V_UINT(com) = V_UINT(java);
					break;
				}

				case VT_UINT | VT_BYREF:
				{
					V_UINT(com) = *V_UINTREF(java);
					break;
				}
			}
			break;
		}

		case VT_UINT | VT_BYREF:
		{
			switch (java->vt)
			{
				case VT_UINT:
				{
					*V_UINTREF(com) = V_UINT(java);
					break;
				}

				case VT_UINT | VT_BYREF:
				{
					*V_UINTREF(com) = *V_UINTREF(java);
					break;
				}
			}
			break;
		}

				case VT_CY:
		{
			switch (java->vt)
			{
				case VT_CY:
				{
					V_CY(com) = V_CY(java);
					break;
				}

				case VT_CY | VT_BYREF:
				{
					V_CY(com) = *V_CYREF(java);
					break;
				}
			}
			break;
		}

		case VT_CY | VT_BYREF:
		{
			switch (java->vt)
			{
				case VT_CY:
				{
					*V_CYREF(com) = V_CY(java);
					break;
				}

				case VT_CY | VT_BYREF:
				{
					*V_CYREF(com) = *V_CYREF(java);
					break;
				}
			}
			break;
		}

				case VT_DATE:
		{
			switch (java->vt)
			{
				case VT_DATE:
				{
					V_DATE(com) = V_DATE(java);
					break;
				}

				case VT_DATE | VT_BYREF:
				{
					V_DATE(com) = *V_DATEREF(java);
					break;
				}
			}
			break;
		}

		case VT_DATE | VT_BYREF:
		{
			switch (java->vt)
			{
				case VT_DATE:
				{
					*V_DATEREF(com) = V_DATE(java);
					break;
				}

				case VT_DATE | VT_BYREF:
				{
					*V_DATEREF(com) = *V_DATEREF(java);
					break;
				}
			}
			break;
		}

				case VT_BSTR:
		{
			switch (java->vt)
			{
				case VT_BSTR:
				{
					V_BSTR(com) = V_BSTR(java);
					break;
				}

				case VT_BSTR | VT_BYREF:
				{
					V_BSTR(com) = *V_BSTRREF(java);
					break;
				}
			}
			break;
		}

		case VT_BSTR | VT_BYREF:
		{
			switch (java->vt)
			{
				case VT_BSTR:
				{
					*V_BSTRREF(com) = V_BSTR(java);
					break;
				}

				case VT_BSTR | VT_BYREF:
				{
					*V_BSTRREF(com) = *V_BSTRREF(java);
					break;
				}
			}
			break;
		}

				case VT_DECIMAL:
		{
			switch (java->vt)
			{
				case VT_DECIMAL:
				{
					V_DECIMAL(com) = V_DECIMAL(java);
					break;
				}

				case VT_DECIMAL | VT_BYREF:
				{
					V_DECIMAL(com) = *V_DECIMALREF(java);
					break;
				}
			}
			break;
		}

		case VT_DECIMAL | VT_BYREF:
		{
			switch (java->vt)
			{
				case VT_DECIMAL:
				{
					*V_DECIMALREF(com) = V_DECIMAL(java);
					break;
				}

				case VT_DECIMAL | VT_BYREF:
				{
					*V_DECIMALREF(com) = *V_DECIMALREF(java);
					break;
				}
			}
			break;
		}


    }
}
Ejemplo n.º 29
0
static HRESULT ExtractArgument(VARIANT * pvArg, WCHAR chIdentifier, BOOL * pbFreeArg, va_list * marker)
{
	HRESULT hr = NOERROR;

	*pbFreeArg = FALSE;

	if (chIdentifier == L'T') chIdentifier = (dh_g_bIsUnicodeMode ? L'S' : L's');

	switch (chIdentifier)
	{
		case L'd':
			V_VT(pvArg)  = VT_I4;
			V_I4(pvArg)  = va_arg(*marker, LONG);
			break;

		case L'u':
			V_VT(pvArg)  = VT_UI4;
			V_UI4(pvArg) = va_arg(*marker, ULONG);
			break;

		case L'e':
			V_VT(pvArg)  = VT_R8;
			V_R8(pvArg)  = va_arg(*marker, DOUBLE);
			break;

		case L'b':
			V_VT(pvArg)   = VT_BOOL;
			V_BOOL(pvArg) = ( va_arg(*marker, BOOL) ? VARIANT_TRUE : VARIANT_FALSE );
			break;

		case L'v':
			*pvArg  = *va_arg(*marker, VARIANT *);
			break;

		case L'm':
			V_VT(pvArg)    = VT_ERROR;
			V_ERROR(pvArg) = DISP_E_PARAMNOTFOUND;
			break;

		case L'B':
			V_VT(pvArg)   = VT_BSTR;
			V_BSTR(pvArg) = va_arg(*marker, BSTR);
			break;

		case L'S':
		{
			LPOLESTR szTemp = va_arg(*marker, LPOLESTR);

			V_VT(pvArg)   = VT_BSTR;
			V_BSTR(pvArg) = SysAllocString(szTemp);

			if (V_BSTR(pvArg) == NULL && szTemp != NULL) hr = E_OUTOFMEMORY;

			*pbFreeArg = TRUE;
			break;
		}

		case L's':
			V_VT(pvArg) = VT_BSTR;
			hr = ConvertAnsiStrToBStr(va_arg(*marker, LPSTR), &V_BSTR(pvArg));
			*pbFreeArg = TRUE;
			break;

		case L'o':
			V_VT(pvArg)       = VT_DISPATCH;
			V_DISPATCH(pvArg) = va_arg(*marker, IDispatch *);
			break;

		case L'O':
			V_VT(pvArg)      = VT_UNKNOWN;
			V_UNKNOWN(pvArg) = va_arg(*marker, IUnknown *);
			break;

		case L'D':
			V_VT(pvArg)   = VT_DATE;
			V_DATE(pvArg) = va_arg(*marker, DATE);
			break;

		case L't':
			V_VT(pvArg) = VT_DATE;
			hr = ConvertTimeTToVariantTime(va_arg(*marker, time_t), &V_DATE(pvArg));
			break;

		case L'W':
			V_VT(pvArg) = VT_DATE;
			hr = ConvertSystemTimeToVariantTime(va_arg(*marker, SYSTEMTIME *), &V_DATE(pvArg));
			break;

		case L'f':
			V_VT(pvArg) = VT_DATE;
			hr = ConvertFileTimeToVariantTime(va_arg(*marker, FILETIME *), &V_DATE(pvArg));
			break;

		case L'p':
#ifndef _WIN64
			V_VT(pvArg) = VT_I4;
			V_I4(pvArg) = (LONG) va_arg(*marker, LPVOID);
#else
			V_VT(pvArg) = VT_I8;
			V_I8(pvArg) = (LONGLONG) va_arg(*marker, LPVOID);
#endif
			break;

		default:
			hr = E_INVALIDARG;
			DEBUG_NOTIFY_INVALID_IDENTIFIER(chIdentifier);
			break;
	}

	return hr;
}
Ejemplo n.º 30
0
STDAPI
VariantChangeType(
    VARIANTARG FAR* pvargDest,
    VARIANTARG FAR* pvargSrc,
    unsigned short wFlags,
    VARTYPE vt)
{
    VARIANT varTmp;
    HRESULT hresult;
    VARTYPE vtSrc;

    if (pvargDest == NULL || pvargSrc == NULL)
      return(E_INVALIDARG);

    vtSrc = V_VT(pvargSrc); // get src vartype

    hresult = NOERROR;          // assume success
    // NOTE: all code after this point must go to LError0 upon Error.

    // should have validated the destination type at this point (to ensure
    // that the below optimized switch statement will work properly).
    switch ( VTSW(vtSrc, vt) )
    {
      case VTSW(VT_BOOL, VT_BOOL):
      case VTSW(VT_I2, VT_I2):
      case VTSW(VT_I4, VT_I4):
      case VTSW(VT_INT, VT_INT):
      case VTSW(VT_I8, VT_I8):
      case VTSW(VT_R4, VT_R4):
      case VTSW(VT_R8, VT_R8):
      case VTSW(VT_CY, VT_CY):
      case VTSW(VT_DECIMAL, VT_DECIMAL):
      case VTSW(VT_I1, VT_I1):
      case VTSW(VT_UI1, VT_UI1):
      case VTSW(VT_UI2, VT_UI2):
      case VTSW(VT_UI4, VT_UI4):
      case VTSW(VT_UINT, VT_UINT):
      case VTSW(VT_UI8, VT_UI8):
        varTmp = *pvargSrc;
        break;

      case VTSW(VT_EMPTY, VT_BSTR):
        hresult = ErrSysAllocString(OASTR(""), &V_BSTR(&varTmp));
        break;

      case VTSW(VT_BOOL, VT_BSTR):
        //fall through to return "0" or "-1"
      case VTSW(VT_I2, VT_BSTR):
        hresult = VarBstrFromI2(V_I2(pvargSrc), LOCALE_USER_DEFAULT, 0, &V_BSTR(&varTmp));
        break;

      case VTSW(VT_I4, VT_BSTR):
      case VTSW(VT_INT, VT_BSTR):
        hresult = VarBstrFromI4(V_I4(pvargSrc), LOCALE_USER_DEFAULT, 0, &V_BSTR(&varTmp));
        break;

      case VTSW(VT_I8, VT_BSTR):
        hresult = VarBstrFromI8(V_I8(pvargSrc), LOCALE_USER_DEFAULT, 0, &V_BSTR(&varTmp));
        break;

      case VTSW(VT_R4, VT_BSTR):
        hresult = VarBstrFromR4(V_R4(pvargSrc), LOCALE_USER_DEFAULT, 0, &V_BSTR(&varTmp));
        break;


      case VTSW(VT_R8, VT_BSTR):
        hresult = VarBstrFromR8(V_R8(pvargSrc), LOCALE_USER_DEFAULT, 0, &V_BSTR(&varTmp));
        break;

      case VTSW(VT_CY, VT_BSTR):
        hresult = VarBstrFromCy(V_CY(pvargSrc), LOCALE_USER_DEFAULT, 0, &V_BSTR(&varTmp));
        break;

      case VTSW(VT_DECIMAL, VT_BSTR):
        hresult = VarBstrFromDec(&pvargSrc->n1.decVal, LOCALE_USER_DEFAULT, 0, &V_BSTR(&varTmp));
        break;

      case VTSW(VT_I1, VT_BSTR):
        hresult = VarBstrFromI1(V_I1(pvargSrc), LOCALE_USER_DEFAULT, 0, &V_BSTR(&varTmp));
        break;

      case VTSW(VT_UI1, VT_BSTR):
        hresult = VarBstrFromUI1(V_UI1(pvargSrc), LOCALE_USER_DEFAULT, 0, &V_BSTR(&varTmp));
        break;

      case VTSW(VT_UI2, VT_BSTR):
        hresult = VarBstrFromUI2(V_UI2(pvargSrc), LOCALE_USER_DEFAULT, 0, &V_BSTR(&varTmp));
        break;

      case VTSW(VT_UI4, VT_BSTR):
      case VTSW(VT_UINT, VT_BSTR):
        hresult = VarBstrFromUI4(V_UI4(pvargSrc), LOCALE_USER_DEFAULT, 0, &V_BSTR(&varTmp));
        break;

      case VTSW(VT_UI8, VT_BSTR):
        hresult = VarBstrFromUI8(V_UI8(pvargSrc), LOCALE_USER_DEFAULT, 0, &V_BSTR(&varTmp));
        break;

      case VTSW(VT_BSTR, VT_BSTR):
        hresult = ErrSysAllocString(V_BSTR(pvargSrc), &V_BSTR(&varTmp));
        break;

      case VTSW(VT_DATE, VT_BSTR):
          _ASSERTE(false);
          hresult = RESULT(DISP_E_TYPEMISMATCH);
          break;

      default:
        if (vtSrc >= VT_VARIANT) {
          IfFailGo(IsLegalVartype(vtSrc), LError0);
        }

        // everybody else gets a type mis-match error
        _ASSERTE(false);
        hresult = RESULT(DISP_E_TYPEMISMATCH);
        break;
    }

    if (FAILED(hresult))
    {
        goto LError0;
    }

    // now set the tag in temp variant.  Errors after this point have to
    // goto LError1 to potentially clear this variant.
    V_VT(&varTmp) = vt;

    // now that we have succeeded, we can go ahead and destroy our
    // destination variant.
    if (V_VT(pvargDest) >= VT_BSTR) {
        IfFailGo(VariantClear(pvargDest), LError1);
    }

    // copy in the variant we just created
    memcpy(pvargDest, &varTmp, sizeof(VARIANT));

    return NOERROR;

LError1:;
    VariantClear(&varTmp);
    // fall through

LError0:;
    return hresult;
}