本文整理汇总了C++中CComVariant::ChangeType方法的典型用法代码示例。如果您正苦于以下问题:C++ CComVariant::ChangeType方法的具体用法?C++ CComVariant::ChangeType怎么用?C++ CComVariant::ChangeType使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类CComVariant
的用法示例。
在下文中一共展示了CComVariant::ChangeType方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: SetNote
void CSubtractiveInstrument::SetNote(CNote *note)
{
// Get a list of all attribute nodes and the
// length of that list
CComPtr<IXMLDOMNamedNodeMap> attributes;
note->Node()->get_attributes(&attributes);
long len;
attributes->get_length(&len);
StringToWaveform(note->Waveform());
// Loop over the list of attributes
for (int i = 0; i < len; i++)
{
// Get attribute i
CComPtr<IXMLDOMNode> attrib;
attributes->get_item(i, &attrib);
// Get the name of the attribute
CComBSTR name;
attrib->get_nodeName(&name);
// Get the value of the attribute. A CComVariant is a variable
// that can have any type. It loads the attribute value as a
// string (UNICODE), but we can then change it to an integer
// (VT_I4) or double (VT_R8) using the ChangeType function
// and then read its integer or double value from a member variable.
CComVariant value;
attrib->get_nodeValue(&value);
if (name == "duration")
{
value.ChangeType(VT_R8);
// number of beats * seconds per beat = seconds for note
SetDuration(value.dblVal);
}
else if (name == "note")
{
SetFreq(NoteToFrequency(value.bstrVal));
}
if (name == "resonfrequency")
{
mResonFilter = true;
value.ChangeType(VT_R8);
mResonFrequency = value.dblVal;
}
// if (name == "resonbandwidth")
// {
// value.ChangeType(VT_R8);
// mResonBandwidth = value.dblVal;
// }
//
// if (name == "filter-envelope")
// {
// mFilterEnvelope = true;
// }
}
}
示例2: AttachImage
STDMETHODIMP CToolBarButton::AttachImage (VARIANT vPicture, VARIANT vIndex, VARIANT vSizeX)
{
HRESULT hr = RetrieveBitmap (vPicture);
if (FAILED(hr)) return hr;
// Argumente konvertieren
CComVariant vArg;
long lIndex = -1;
long lSizeX = 0;
hr = vArg.ChangeType (VT_I4, &vIndex);
if (SUCCEEDED(hr)) lIndex = V_I4(&vArg);
hr = vArg.ChangeType (VT_I4, &vSizeX);
if (SUCCEEDED(hr)) lSizeX = V_I4(&vArg);
if (lIndex >= 0 && 0 == lSizeX)
return E_INVALIDARG; // Größe muß gegeben sein
// wenn kein Index gegeben ist, dann die Bitmap direkt verwenden
if (lIndex < 0) return S_OK;
// ansonsten generieren des gewünschten Ausschnittes
// ...
m_PictDisp.Assign(NULL); // wieder freigeben
return E_NOTIMPL;
}
示例3: WalkTree
////////////////////////////////////////////////////////////////////////////
// Helper function: Walk all the Elements at a particular node
////////////////////////////////////////////////////////////////////////////
HRESULT CXMLDocument::WalkTree(int iLevel, MSXML2::IXMLDOMNode* pNode)
{
HRESULT hr = S_OK;
CComBSTR bstrNodeName;
pNode->get_nodeName(&bstrNodeName);
CComVariant vNodeValue;
pNode->get_nodeValue(&vNodeValue);
vNodeValue.ChangeType(VT_BSTR);
CString strValueString = V_BSTR(&vNodeValue);
if (m_pCallbackFunction)
m_pCallbackFunction(iLevel, CString(bstrNodeName), (LPCSTR)NULL, strValueString, m_pCallbackParam);
MSXML2::IXMLDOMNamedNodeMapPtr pAttributes = NULL;
if (SUCCEEDED(pNode->get_attributes(&pAttributes)) && (pAttributes != NULL))
{
MSXML2::IXMLDOMNodePtr pAttribute = NULL;
pAttributes->nextNode(&pAttribute);
bool bRetVal = true;
while (pAttribute)
{
CComBSTR bstrAttribName;
pAttribute->get_nodeName(&bstrAttribName);
CComVariant vNodeValue;
pAttribute->get_nodeValue(&vNodeValue);
vNodeValue.ChangeType(VT_BSTR);
CString strValueString = V_BSTR(&vNodeValue);
if (m_pCallbackFunction)
bRetVal = m_pCallbackFunction(iLevel+1, CString(bstrNodeName), CString(bstrAttribName), strValueString, m_pCallbackParam);
if (!bRetVal)
{
// set complete error message with node name and all attribute values
m_strErrorNode = bstrNodeName;
return S_FALSE;
}
pAttributes->nextNode(&pAttribute);
}
}
MSXML2::IXMLDOMNodePtr pChild = NULL;
pNode->get_firstChild(&pChild);
while (pChild)
{
if (WalkTree(iLevel+1, pChild) != S_OK)
return S_FALSE;
MSXML2::IXMLDOMNode* pNext = NULL;
pChild->get_nextSibling(&pNext);
pChild = pNext;
}
return S_OK;
}
示例4: SetNote
void CWaveInstrument::SetNote(CNote *note)
{
// Get a list of all attribute nodes and the
// length of that list
CComPtr<IXMLDOMNamedNodeMap> attributes;
note->Node()->get_attributes(&attributes);
long len;
attributes->get_length(&len);
// Loop over the list of attributes
for(int i=0; i<len; i++)
{
// Get attribute i
CComPtr<IXMLDOMNode> attrib;
attributes->get_item(i, &attrib);
// Get the name of the attribute
CComBSTR name;
attrib->get_nodeName(&name);
// Get the value of the attribute. A CComVariant is a variable
// that can have any type. It loads the attribute value as a
// string (UNICODE), but we can then change it to an integer
// (VT_I4) or double (VT_R8) using the ChangeType function
// and then read its integer or double value from a member variable.
CComVariant value;
attrib->get_nodeValue(&value);
if(name == "duration")
{
value.ChangeType(VT_R8);
SetDuration(value.dblVal);
}
else if(name == "note")
{
m_freq = NoteToFrequency(L"C5") - NoteToFrequency(value.bstrVal);
}
else if(name == "measure")
{
value.ChangeType(VT_R8);
if(value.dblVal == 1.0)
{
m_attack = 0.04;
m_release = 0.06;
}
else if((value.dblVal - int(value.dblVal)) >= 0)
{
m_attack = 0.04;
m_release = 0.04;
}
}
}
}
示例5: SetNote
void CWaveInstrumentB::SetNote(CNote *note)
{
// Get a list of all attribute nodes and the
// length of that list
CComPtr<IXMLDOMNamedNodeMap> attributes;
note->Node()->get_attributes(&attributes);
long len;
attributes->get_length(&len);
// Loop over the list of attributes
for(int i=0; i<len; i++)
{
// Get attribute i
CComPtr<IXMLDOMNode> attrib;
attributes->get_item(i, &attrib);
// Get the name of the attribute
CComBSTR name;
attrib->get_nodeName(&name);
CComVariant value;
attrib->get_nodeValue(&value);
if(name == "duration")
{
value.ChangeType(VT_R8);
SetDuration(value.dblVal);
}
else if(name == "attack")
{
value.ChangeType(VT_R8);
m_ar.SetAttack(value.dblVal);
}
else if(name == "release")
{
value.ChangeType(VT_R8);
m_ar.SetRelease(value.dblVal);
}
else if(name == "decay")
{
value.ChangeType(VT_R8);
m_ar.SetDecay(value.dblVal);
}
else if(name == "sustain")
{
value.ChangeType(VT_R8);
m_ar.SetSustain(value.dblVal);
}
}
}
示例6: GetElementID
HRESULT CPageEvents::GetElementID(IXMLDOMElement* pElem, int* pID)
{
// Get the id or LowerBound attribute, in that order
CComVariant var;
if (FAILED(pElem->getAttribute(m_bstrID, &var)) ||
FAILED(var.ChangeType(VT_I4)))
{
RETURN_FAILED(pElem->getAttribute(m_bstrLowerBound, &var));
RETURN_FAILED(var.ChangeType(VT_I4));
}
*pID = V_I4(&var);
return S_OK;
}
示例7: _getWmiInfo
tstring CCliMgr::_getWmiInfo(IWbemClassObject *pClassObject,LPCTSTR lpszField)
{
SAFEARRAY *pvNames = NULL;
tstring lpszText2;
CComVariant varValue ;
_bstr_t bstrName(lpszField);
if( pClassObject->Get( bstrName , 0 , &varValue , NULL , 0 ) == S_OK )
{
if(varValue.vt == VT_NULL || varValue.vt == VT_EMPTY || varValue.vt == VT_ERROR)
return lpszText2;
_bstr_t b;
if( varValue.vt & VT_BSTR )
{
b = &varValue;
lpszText2 = tstring(b);
}
else if( varValue.vt & VT_ARRAY )
{
long iLowBound = 0 , iUpBound = 0 ;
SafeArrayGetLBound( varValue.parray , 1 , &iLowBound ) ;
SafeArrayGetUBound( varValue.parray , 1 , &iUpBound ) ;
for( long j = iLowBound ; j <= iUpBound ; j ++ )
{
VARIANT *pvar = NULL ;
long temp = j ;
if( SafeArrayGetElement( varValue.parray , &temp , pvar ) == S_OK &&
pvar )
{
CComVariant varTemp ;
if( varTemp.ChangeType( VT_BSTR , pvar ) == S_OK )
{
if( !lpszText2.empty() )
lpszText2 += _T(",") ;
b = &varTemp;
lpszText2 += tstring(b) ;
}
}
}
}
else
{
if( varValue.ChangeType( VT_BSTR ) == S_OK )
{
b = &varValue;
lpszText2 += tstring(b) ;
}
}
}
return lpszText2 ;
}
示例8: InitializeCodecContextFromHaaliInfo
FFCodecContext InitializeCodecContextFromHaaliInfo(CComQIPtr<IPropertyBag> pBag) {
CComVariant pV;
if (FAILED(pBag->Read(L"Type", &pV, NULL)) && SUCCEEDED(pV.ChangeType(VT_UI4)))
return FFCodecContext();
unsigned int TT = pV.uintVal;
FFCodecContext CodecContext(avcodec_alloc_context3(NULL), DeleteHaaliCodecContext);
unsigned int FourCC = 0;
if (TT == TT_VIDEO) {
pV.Clear();
if (SUCCEEDED(pBag->Read(L"Video.PixelWidth", &pV, NULL)) && SUCCEEDED(pV.ChangeType(VT_UI4)))
CodecContext->coded_width = pV.uintVal;
pV.Clear();
if (SUCCEEDED(pBag->Read(L"Video.PixelHeight", &pV, NULL)) && SUCCEEDED(pV.ChangeType(VT_UI4)))
CodecContext->coded_height = pV.uintVal;
pV.Clear();
if (SUCCEEDED(pBag->Read(L"FOURCC", &pV, NULL)) && SUCCEEDED(pV.ChangeType(VT_UI4)))
FourCC = pV.uintVal;
pV.Clear();
if (SUCCEEDED(pBag->Read(L"CodecPrivate", &pV, NULL))) {
CodecContext->extradata_size = vtSize(pV);
CodecContext->extradata = static_cast<uint8_t*>(av_mallocz(CodecContext->extradata_size + FF_INPUT_BUFFER_PADDING_SIZE));
vtCopy(pV, CodecContext->extradata);
}
}
else if (TT == TT_AUDIO) {
pV.Clear();
if (SUCCEEDED(pBag->Read(L"CodecPrivate", &pV, NULL))) {
CodecContext->extradata_size = vtSize(pV);
CodecContext->extradata = static_cast<uint8_t*>(av_mallocz(CodecContext->extradata_size + FF_INPUT_BUFFER_PADDING_SIZE));
vtCopy(pV, CodecContext->extradata);
}
pV.Clear();
if (SUCCEEDED(pBag->Read(L"Audio.SamplingFreq", &pV, NULL)) && SUCCEEDED(pV.ChangeType(VT_UI4)))
CodecContext->sample_rate = pV.uintVal;
pV.Clear();
if (SUCCEEDED(pBag->Read(L"Audio.BitDepth", &pV, NULL)) && SUCCEEDED(pV.ChangeType(VT_UI4)))
CodecContext->bits_per_coded_sample = pV.uintVal;
pV.Clear();
if (SUCCEEDED(pBag->Read(L"Audio.Channels", &pV, NULL)) && SUCCEEDED(pV.ChangeType(VT_UI4)))
CodecContext->channels = pV.uintVal;
}
pV.Clear();
if (SUCCEEDED(pBag->Read(L"CodecID", &pV, NULL)) && SUCCEEDED(pV.ChangeType(VT_BSTR))) {
char CodecStr[2048];
wcstombs(CodecStr, pV.bstrVal, 2000);
CodecContext->codec = avcodec_find_decoder(MatroskaToFFCodecID(CodecStr, CodecContext->extradata, FourCC, CodecContext->bits_per_coded_sample));
}
return CodecContext;
}
示例9: WalkTree
////////////////////////////////////////////////////////////////////////////
// Helper function: Walk all the Elements at a particular node
////////////////////////////////////////////////////////////////////////////
HRESULT CXMLDocument::WalkTree(int iLevel, MSXML::IXMLDOMNode* pNode)
{
HRESULT hr = S_OK;
CComBSTR bstrNodeName;
pNode->get_nodeName(&bstrNodeName);
CComVariant vNodeValue;
pNode->get_nodeValue(&vNodeValue);
vNodeValue.ChangeType(VT_BSTR);
CString strValueString = V_BSTR(&vNodeValue);
if (m_pCallbackFunction)
m_pCallbackFunction(iLevel, CString(bstrNodeName), strValueString, m_pCallbackParam);
MSXML::IXMLDOMNamedNodeMapPtr pAttributes = NULL;
if (SUCCEEDED(pNode->get_attributes(&pAttributes)) && (pAttributes != NULL))
{
MSXML::IXMLDOMNodePtr pAttribute = NULL;
pAttributes->nextNode(&pAttribute);
while (pAttribute)
{
CComBSTR bstrNodeName;
pAttribute->get_nodeName(&bstrNodeName);
CComVariant vNodeValue;
pAttribute->get_nodeValue(&vNodeValue);
vNodeValue.ChangeType(VT_BSTR);
CString strValueString = V_BSTR(&vNodeValue);
if (m_pCallbackFunction)
m_pCallbackFunction(iLevel+1, CString(bstrNodeName), strValueString, m_pCallbackParam);
pAttributes->nextNode(&pAttribute);
}
}
MSXML::IXMLDOMNodePtr pChild = NULL;
pNode->get_firstChild(&pChild);
while (pChild)
{
WalkTree(iLevel+1, pChild);
MSXML::IXMLDOMNode* pNext = NULL;
pChild->get_nextSibling(&pNext);
pChild = pNext;
}
return S_OK;
}
示例10: XmlLoad
void CNote::XmlLoad(IXMLDOMNode * xml, std::wstring & instrument, CEffectsSendTable *sendTable)
{
// Remember the xml node and the instrument.
m_node = xml;
m_instrument = instrument;
m_sendTable = *sendTable;
// Get a list of all attribute nodes and the
// length of that list
CComPtr<IXMLDOMNamedNodeMap> attributes;
xml->get_attributes(&attributes);
long len;
attributes->get_length(&len);
// Loop over the list of attributes
for(int i=0; i<len; i++)
{
// Get attribute i
CComPtr<IXMLDOMNode> attrib;
attributes->get_item(i, &attrib);
// Get the name of the attribute
CComBSTR name;
attrib->get_nodeName(&name);
// Get the value of the attribute.
CComVariant value;
attrib->get_nodeValue(&value);
if(name == "measure")
{
if(m_measure < 0)
{
// The file has measures that start at 1.
// We'll make them start at zero instead.
value.ChangeType(VT_I4);
m_measure = value.intVal - 1 + m_repeat;
}
}
else if(name == "beat")
{
// Same thing for the beats.
value.ChangeType(VT_R8);
m_beat = value.dblVal - 1;
}
}
}
示例11: UpdateWhere
STDMETHODIMP CXRecords::UpdateWhere(BSTR key, VARIANT newVal, BSTR whereKey, BSTR op, VARIANT v1, VARIANT v2, long* pVal)
{
CXRSWhere where;
HRESULT hr;
hr = where.Prepare(m_pFields, whereKey, op, v1, v2);
if(FAILED(hr))return hr;
int count = m_listRecords->GetCount();
int i, n = 0;
int index = m_pFields->FindField(key);
if(index < 0 || index >= (int)m_pFields->GetCount())
return DISP_E_BADINDEX;
VARTYPE vt = m_pFields->GetValue(index)->m_nType;
if(vt == VT_DISPATCH)return E_INVALIDARG;
CComVariant var;
hr = var.ChangeType(vt, &newVal);
if(FAILED(hr))return hr;
for(i = 0; i < count; i ++)
if(where.Check(m_listRecords->GetValue(i)))
{
*(CComVariant*)&(m_listRecords->GetValue(i)->m_arrayVariant[index]) = var;
n ++;
}
*pVal = n;
return S_OK;
}
示例12: StrToBin
VARIANT CBoxEncoding::StrToBin(VARIANT& var, VARIANT &varCP)
{
CBoxBinPtr varString(var, VT_BSTR);
UINT nCodePage;
if(varCP.vt == VT_ERROR)
nCodePage = _AtlGetConversionACP();
else
{
CComVariant varTemp;
varTemp.ChangeType(VT_I4, &varCP);
if(varTemp.vt == VT_I4)
nCodePage = varTemp.lVal;
else
AfxThrowOleException(TYPE_E_TYPEMISMATCH);
}
int _nTempCount = ::WideCharToMultiByte(nCodePage, 0, LPWSTR(varString.m_pData), varString.m_nSize, NULL, 0, NULL, NULL);
CBoxBinPtr varPtr(_nTempCount);
::WideCharToMultiByte(nCodePage, 0, LPWSTR(varString.m_pData), varString.m_nSize, varPtr, _nTempCount, NULL, NULL);
return varPtr;
}
示例13: ConvertBSTRToMBS
std::vector<std::string> get_properties(
const wchar_t * i_query, const std::vector<const wchar_t *> & i_property_names)
{
auto query_results = execute_query(i_query);
std::vector<std::string> value_strs;
value_strs.resize(i_property_names.size());
for (size_t property_index = 0; property_index < i_property_names.size();
property_index++)
{
for (const auto & result : query_results)
{
auto & value_str = value_strs[property_index];
if (value_str.length() > 0)
{
value_str += ", ";
}
CComVariant value;
CIMTYPE value_type;
TESTITY_COM_CALL(
result->Get(i_property_names[property_index], 0, &value, &value_type, NULL));
value.ChangeType(VT_BSTR);
value_str += ConvertBSTRToMBS(value.bstrVal);
}
}
return value_strs;
}
示例14: CreateStringFromStream
// die folgende Funktion ist das konkrete äquivalent für 'OleLoadFromStream' --
HRESULT CreateStringFromStream (IStream *pIStream, LPSTR lpstr, int iLen)
{
ASSERT(pIStream);
ASSERT(lpstr);
ASSERT(0 < iLen);
if (NULL == lpstr) return E_POINTER;
if (0 == iLen) return E_INVALIDARG;
USES_CONVERSION;
*lpstr = '\0';
try
{ // Variant liest sich selbst vom Stream
CComVariant cv;// VariantInit()
HRESULT hr = cv.ReadFromStream (pIStream);
if (FAILED(hr)) _com_issue_error(hr);
// Richtigen Typ rausholen
hr = cv.ChangeType (VT_BSTR);
if (FAILED(hr)) _com_issue_error(hr);
// Wert lesen
CComBSTR bstr = cv.bstrVal; // SysAllocString(...
LPSTR lpstrName = OLE2A(bstr.m_str);
if (iLen < strlen(lpstrName)) _com_issue_error(E_INVALIDARG);
strcpy(lpstr, lpstrName);
// in ~CComVariant() VariantClear()
} // in ~CComBSTR() SysFreeString(m_str)
catch (_com_error& e)
{
return _COM_ERROR(e);
}
return NOERROR;
}
示例15: getLabviewValue
void lvDCOMInterface::getLabviewValue(const char* param, T* value)
{
if (value == NULL)
{
throw std::runtime_error("getLabviewValue failed (NULL)");
}
if (param == NULL || *param == '\0')
{
throw std::runtime_error("getLabviewValue: param is NULL");
}
CComVariant v;
char vi_name_xpath[MAX_PATH_LEN], control_name_xpath[MAX_PATH_LEN];
_snprintf(vi_name_xpath, sizeof(vi_name_xpath), "/lvinput/section[@name='%s']/vi/@path", m_configSection.c_str());
_snprintf(control_name_xpath, sizeof(control_name_xpath), "/lvinput/section[@name='%s']/vi/param[@name='%s']/read/@target", m_configSection.c_str(), param);
CComBSTR vi_name(doPath(vi_name_xpath).c_str());
CComBSTR control_name(doXPATH(control_name_xpath).c_str());
if (vi_name.Length() == 0 || control_name.Length() == 0)
{
throw std::runtime_error("getLabviewValue: vi or control is NULL");
}
getLabviewValue(vi_name, control_name, &v);
if ( v.ChangeType(CVarTypeInfo<T>::VT) == S_OK )
{
*value = v.*(CVarTypeInfo<T>::pmField);
}
else
{
throw std::runtime_error("getLabviewValue failed (ChangeType)");
}
}