本文整理汇总了C++中VariantChangeType函数的典型用法代码示例。如果您正苦于以下问题:C++ VariantChangeType函数的具体用法?C++ VariantChangeType怎么用?C++ VariantChangeType使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了VariantChangeType函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: VariantInit
long CStringCollect::Remove(const VARIANT FAR& removeValue)
{
int nIndex = -1;
VARIANT varTemp;
VariantInit(&varTemp);
const VARIANT* pvar = &removeValue;
if (removeValue.vt != VT_BSTR)
{
if (VariantChangeType(&varTemp, (VARIANT*)&removeValue, 0, VT_I4) == NOERROR)
pvar = &varTemp;
else if (VariantChangeType(&varTemp, (VARIANT*)&removeValue, 0, VT_BSTR) == NOERROR)
pvar = &varTemp;
else
AfxThrowOleException(DISP_E_TYPEMISMATCH);
}
if (pvar->vt == VT_BSTR)
nIndex = (int)Find(CString(pvar->bstrVal));
else if (pvar->vt == VT_I4)
nIndex = (int)pvar->lVal;
VariantClear(&varTemp);
CheckIndex(nIndex);
m_strArray.RemoveAt(nIndex);
return (long)m_strArray.GetSize();
}
示例2: WshShell3_Run
static HRESULT WINAPI WshShell3_Run(IWshShell3 *iface, BSTR cmd, VARIANT *style, VARIANT *WaitOnReturn, int *exit_code)
{
SHELLEXECUTEINFOW info;
int waitforprocess;
VARIANT s, w;
HRESULT hr;
TRACE("(%s %s %s %p)\n", debugstr_w(cmd), debugstr_variant(style), debugstr_variant(WaitOnReturn), exit_code);
VariantInit(&s);
hr = VariantChangeType(&s, style, 0, VT_I4);
if (FAILED(hr))
{
ERR("failed to convert style argument, 0x%08x\n", hr);
return hr;
}
VariantInit(&w);
hr = VariantChangeType(&w, WaitOnReturn, 0, VT_I4);
if (FAILED(hr))
{
ERR("failed to convert wait argument, 0x%08x\n", hr);
return hr;
}
memset(&info, 0, sizeof(info));
info.cbSize = sizeof(info);
waitforprocess = V_I4(&w);
info.fMask = waitforprocess ? SEE_MASK_NOASYNC | SEE_MASK_NOCLOSEPROCESS : SEE_MASK_DEFAULT;
info.lpFile = cmd;
info.nShow = V_I4(&s);
if (!ShellExecuteExW(&info))
{
TRACE("ShellExecute failed, %d\n", GetLastError());
return HRESULT_FROM_WIN32(GetLastError());
}
else
{
if (waitforprocess)
{
if (exit_code)
{
DWORD code;
GetExitCodeProcess(info.hProcess, &code);
*exit_code = code;
}
CloseHandle(info.hProcess);
}
else
if (exit_code) *exit_code = 0;
return S_OK;
}
}
示例3: httprequest_open
static HRESULT WINAPI httprequest_open(IXMLHTTPRequest *iface, BSTR method, BSTR url,
VARIANT async, VARIANT user, VARIANT password)
{
httprequest *This = impl_from_IXMLHTTPRequest( iface );
HRESULT hr;
VARIANT str, is_async;
TRACE("(%p)->(%s %s %s)\n", This, debugstr_w(method), debugstr_w(url),
debugstr_variant(&async));
if (!method || !url) return E_INVALIDARG;
/* free previously set data */
SysFreeString(This->url);
SysFreeString(This->user);
SysFreeString(This->password);
This->url = This->user = This->password = NULL;
if (lstrcmpiW(method, MethodGetW) == 0)
{
This->verb = BINDVERB_GET;
}
else if (lstrcmpiW(method, MethodPutW) == 0)
{
This->verb = BINDVERB_PUT;
}
else if (lstrcmpiW(method, MethodPostW) == 0)
{
This->verb = BINDVERB_POST;
}
else
{
FIXME("unsupported request type %s\n", debugstr_w(method));
This->verb = -1;
return E_FAIL;
}
This->url = SysAllocString(url);
VariantInit(&is_async);
hr = VariantChangeType(&is_async, &async, 0, VT_BOOL);
This->async = hr == S_OK && V_BOOL(&is_async) == VARIANT_TRUE;
VariantInit(&str);
hr = VariantChangeType(&str, &user, 0, VT_BSTR);
if (hr == S_OK)
This->user = V_BSTR(&str);
hr = VariantChangeType(&str, &password, 0, VT_BSTR);
if (hr == S_OK)
This->password = V_BSTR(&str);
httprequest_setreadystate(This, READYSTATE_LOADING);
return S_OK;
}
示例4: CreatePopupMenu
STDMETHODIMP CDrawMenu::Popup(/*[in, optional] */VARIANT X, /*[in, optional] */VARIANT Y)
{
USES_CONVERSION;
int nCount = m_arrItems.GetSize();
if (nCount == 0)
return S_FALSE;
HMENU hMenu = CreatePopupMenu();
if (hMenu == NULL)
return E_FAIL;
int nIndex = 0;
AddMenuItems(hMenu, nIndex, 0);
HWND hWndParent = GetClientWindow();
POINT pt;
GetCursorPos(&pt);
ScreenToClient(hWndParent, &pt);
if (X.vt != VT_ERROR)
{
VariantChangeType(&X, &X, 0, VT_I4);
pt.x = X.intVal;
}
if (Y.vt != VT_ERROR)
{
VariantChangeType(&Y, &Y, 0, VT_I4);
pt.y = Y.intVal;
}
ClientToScreen(hWndParent, &pt);
Fire_Event(2);
// 2011.4.25: 鼠标按下时弹出菜单时,释放鼠标捕获
SetCapture(FALSE);
int nRet = TrackPopupMenu(hMenu, TPM_LEFTALIGN | TPM_TOPALIGN | TPM_NONOTIFY | TPM_RETURNCMD,
pt.x, pt.y, 0, hWndParent, 0);
if (nRet > 0 && nRet <= m_arrItems.GetSize())
{
CMenuItem& item = m_arrItems[nRet - 1];
Fire_MenuClick(nRet, item.m_bstrID);
}
DestroyMenu(hMenu);
Fire_Event(3);
return S_OK;
}
示例5: VariantInit
STDMETHODIMP CPoint::SetCoords2(/*[in]*/ VARIANT x, /*[in]*/ VARIANT y) {
VARIANT vx, vy;
VariantInit(&vx);
VariantInit(&vy);
VariantChangeType(&vx, &x, 0, VT_I4);
VariantChangeType(&vy, &y, 0, VT_I4);
m_x = vx.lVal;
m_y = vy.lVal;
VariantClear(&vx);
VariantClear(&vy);
return S_OK;
}
示例6: V_VT
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;
}
}
示例7: Java_com_tangram_Variant_toEnumVariant
/**
* Converts the data to a Enum Variant object and then returns it as a Dispatch
*/
JNIEXPORT jobject JNICALL Java_com_tangram_Variant_toEnumVariant(JNIEnv *env, jobject _this)
{
VARIANT *v = extractVariant(env, _this);
if (v)
{
HRESULT hr;
if (FAILED(hr = VariantChangeType(v, v, 0, VT_UNKNOWN))) {
ThrowComFail(env, "VariantChangeType failed", hr);
return NULL;
}
jclass autoClass = env->FindClass("com/tangram/EnumVariant");
jmethodID autoCons =
env->GetMethodID(autoClass, "<init>", "(J)V");
// construct an Unknown object to return
IUnknown *unk = V_UNKNOWN(v);
IEnumVARIANT *ie;
hr = unk->QueryInterface(IID_IEnumVARIANT, (void **)&ie);
if (FAILED(hr)) {
ThrowComFail(env, "[toEnumVariant]: Object does not implement IEnumVariant", hr);
return NULL;
}
// I am copying the pointer to java
// SF-1674179 fix EnumVariants memory leak
// AJ: yes, but the QueryInterface call above already incremented the reference
//if (ie) ie->AddRef();
jobject newAuto = env->NewObject(autoClass, autoCons, ie);
return newAuto;
}
return NULL;
}
示例8: _AfxCoerceNumber
BOOL AFXAPI _AfxCoerceNumber(void* pvDst, VARTYPE vtDst, void* pvSrc, VARTYPE vtSrc)
{
// Check size of source.
size_t cbSrc = _AfxGetSizeOfVarType(vtSrc);
if (cbSrc == 0)
return FALSE;
// If source and destination are same type, just copy.
if (vtSrc == vtDst)
{
memcpy(pvDst, pvSrc, cbSrc);
return TRUE;
}
// Check size of destination.
size_t cbDst = _AfxGetSizeOfVarType(vtDst);
if (cbDst == 0)
return FALSE;
// Initialize variant for coercion.
VARIANTARG var;
V_VT(&var) = vtSrc;
memcpy((void*)&V_NONE(&var), pvSrc, cbSrc);
// Do the coercion.
if (FAILED(VariantChangeType(&var, &var, 0, vtDst)))
return FALSE;
// Copy result to destination.
memcpy(pvDst, (void*)&V_NONE(&var), cbDst);
return TRUE;
}
示例9: CheckNull
HRESULT CModuleConfiguration::GetDWORD(IAppHostElement* section, LPCWSTR propertyName, DWORD* value)
{
HRESULT hr = S_OK;
BSTR sysPropertyName = NULL;
IAppHostProperty* prop = NULL;
VARIANT var;
CheckNull(value);
*value = 0;
VariantInit(&var);
ErrorIf(NULL == (sysPropertyName = SysAllocString(propertyName)), ERROR_NOT_ENOUGH_MEMORY);
CheckError(section->GetPropertyByName(sysPropertyName, &prop));
CheckError(prop->get_Value(&var));
CheckError(VariantChangeType(&var, &var, 0, VT_UI4));
*value = var.ulVal;
Error:
VariantClear(&var);
if ( sysPropertyName )
{
SysFreeString(sysPropertyName);
sysPropertyName = NULL;
}
if (prop)
{
prop->Release();
prop = NULL;
}
return hr;
}
示例10: _T
//------------------------------------------------------------------------//
BOOL CBCGPGlobalUtils::CyFromString(CY& cy, LPCTSTR psz)
{
USES_CONVERSION;
if (psz == NULL || _tcslen (psz) == 0)
{
psz = _T("0");
}
VARIANTARG varBstr;
VARIANTARG varCy;
AfxVariantInit(&varBstr);
AfxVariantInit(&varCy);
V_VT(&varBstr) = VT_BSTR;
V_BSTR(&varBstr) = SysAllocString(T2COLE(psz));
if (FAILED(VariantChangeType(&varCy, &varBstr, 0, VT_CY)))
{
VariantClear(&varBstr);
VariantClear(&varCy);
return FALSE;
}
cy = V_CY(&varCy);
VariantClear(&varBstr);
VariantClear(&varCy);
return TRUE;
}
示例11: VariantChangeType
STDMETHODIMP CPmcDB::readArchiveValue(
BSTR tagName,
VARIANT date,
VARIANT * tagValue
)
{
SYSTEMTIME st;
FILETIME ft;
TAG_NAME tn;
hislog_item_t value;
VARIANT dd;
HRESULT hr;
if(date.vt != VT_DATE){
// BUGBUG: not tested
hr = VariantChangeType(&dd, &date, 0, VT_DATE);
if(FAILED(hr)){
return hr;
}
date = dd;
}
VariantTimeToSystemTime(date.date, &st);
SystemTimeToFileTime(&st, &ft);
tagname_by_textW(&tn, tagName);
queryHisData(&tn, &ft, 1, 1);
getHisData(&value);
pmc_value_to_variant(&value, tagValue);
return S_OK;
}
示例12: Java_com_tangram_Variant_changeVariantType
/**
* changes the type of the underlying variant data
* */
JNIEXPORT void JNICALL Java_com_tangram_Variant_changeVariantType(JNIEnv *env, jobject _this, jshort t)
{
VARIANT *v = extractVariant(env, _this);
if (v) {
VariantChangeType(v, v, 0, t);
}
}
示例13: dhEnumNextObject
HRESULT dhEnumNextObject(IEnumVARIANT * pEnum, IDispatch ** ppDisp)
{
VARIANT vtResult;
HRESULT hr;
DH_ENTER(L"EnumNextObject");
if (!pEnum || !ppDisp) return DH_EXIT(E_INVALIDARG, L"Enumerator");
hr = pEnum->lpVtbl->Next(pEnum, 1, &vtResult, NULL);
if (hr == S_OK)
{
if (vtResult.vt == VT_DISPATCH)
{
*ppDisp = vtResult.pdispVal;
}
else
{
hr = VariantChangeType(&vtResult, &vtResult, 0, VT_DISPATCH);
if (SUCCEEDED(hr)) *ppDisp = vtResult.pdispVal;
else VariantClear(&vtResult);
}
}
return DH_EXIT(hr, L"Enumerator");
}
示例14: zbx_wmi_get
/******************************************************************************
* *
* Function: zbx_wmi_get *
* *
* Purpose: wrapper function for zbx_wmi_get_variant(), stores the retrieved *
* WMI value as UTF-8 encoded string *
* *
* Parameters: wmi_namespace [IN] - object path of the WMI namespace (UTF-8) *
* wmi_query [IN] - WQL query (UTF-8) *
* utf8_value [OUT] - address of the pointer to the retrieved *
* value (dynamically allocated) *
* *
* Comments: if either retrieval or type conversion failed then *utf8_value *
* remains unchanged (set it to NULL before calling this function *
* to check for this condition). Callers must free *utf8_value. *
* *
******************************************************************************/
extern "C" void zbx_wmi_get(const char *wmi_namespace, const char *wmi_query, char **utf8_value)
{
VARIANT vtProp;
HRESULT hres;
VariantInit(&vtProp);
if (SUCCEED != zbx_co_initialize())
{
zabbix_log(LOG_LEVEL_DEBUG, "cannot initialize COM library for querying WMI");
goto out;
}
if (SYSINFO_RET_FAIL == zbx_wmi_get_variant(wmi_namespace, wmi_query, &vtProp))
{
zabbix_log(LOG_LEVEL_DEBUG, "cannot get WMI result");
goto out;
}
hres = VariantChangeType(&vtProp, &vtProp, VARIANT_ALPHABOOL, VT_BSTR);
if (FAILED(hres))
{
zabbix_log(LOG_LEVEL_DEBUG, "cannot convert WMI result of type %d to VT_BSTR", vtProp.vt);
goto out;
}
*utf8_value = zbx_unicode_to_utf8((wchar_t *)_bstr_t(vtProp.bstrVal));
out:
VariantClear(&vtProp);
}
示例15: getStyleAttribute
static void getStyleAttribute (IDispatch *object, std::string &style)
{
VARIANT v;
VariantInit(&v);
HRESULT hr = getDispatchProperty(object, "style", v);
if ( FAILED (hr))
return;
if (! v.vt == VT_DISPATCH)
{
VariantClear(&v);
return;
}
VARIANT v2;
VariantInit (&v2);
hr = getDispatchProperty(v.pdispVal, "cssText", v2);
if ( !FAILED(hr))
{
VARIANT result2;
VariantInit(&result2);
if ( S_OK == VariantChangeType (&result2, &v2, 0, VT_BSTR))
{
Utils::bstr2str (style, result2.bstrVal);
VariantClear (&result2);
} else {
}
VariantClear (&v2);
}
v.pdispVal->Release();
VariantClear(&v);
}