static void test_change_type(IVariantChangeType *change_type, VARIANT *src, const conv_results_t *ex) { VARIANT v; call_change_type(change_type, &v, src, VT_I4); ok(V_I4(&v) == ex->int_result, "V_I4(v) = %d, expected %d\n", V_I4(&v), ex->int_result); call_change_type(change_type, &v, src, VT_BSTR); ok(!strcmp_wa(V_BSTR(&v), ex->str_result), "V_BSTR(v) = %s, expected %s\n", wine_dbgstr_w(V_BSTR(&v)), ex->str_result); VariantClear(&v); call_change_type(change_type, &v, src, VT_BOOL); ok(V_BOOL(&v) == ex->bool_result, "V_BOOL(v) = %x, expected %x\n", V_BOOL(&v), ex->bool_result); if(ex->test_double) { call_change_type(change_type, &v, src, VT_R8); ok(V_R8(&v) == ex->double_result, "V_R8(v) = %lf, expected %lf\n", V_R8(&v), ex->double_result); call_change_type(change_type, &v, src, VT_R4); ok(V_R4(&v) == (float)ex->double_result, "V_R4(v) = %f, expected %f\n", V_R4(&v), (float)ex->double_result); } if(V_VT(src) == VT_NULL) call_change_type(change_type, &v, src, VT_NULL); else change_type_fail(change_type, src, VT_NULL, E_NOTIMPL); if(V_VT(src) == VT_EMPTY) call_change_type(change_type, &v, src, VT_EMPTY); else change_type_fail(change_type, src, VT_EMPTY, E_NOTIMPL); call_change_type(change_type, &v, src, VT_I2); ok(V_I2(&v) == (INT16)ex->int_result, "V_I2(v) = %d, expected %d\n", V_I2(&v), ex->int_result); }
static HRESULT error_constr(script_ctx_t *ctx, WORD flags, DISPPARAMS *dp, VARIANT *retv, jsexcept_t *ei, DispatchEx *constr) { DispatchEx *err; VARIANT numv; UINT num; BSTR msg = NULL; HRESULT hres; V_VT(&numv) = VT_NULL; if(arg_cnt(dp)) { hres = to_number(ctx, get_arg(dp, 0), ei, &numv); if(FAILED(hres) || (V_VT(&numv)==VT_R8 && isnan(V_R8(&numv)))) hres = to_string(ctx, get_arg(dp, 0), ei, &msg); else if(V_VT(&numv) == VT_I4) num = V_I4(&numv); else num = V_R8(&numv); if(FAILED(hres)) return hres; } if(arg_cnt(dp)>1 && !msg) { hres = to_string(ctx, get_arg(dp, 1), ei, &msg); if(FAILED(hres)) return hres; } switch(flags) { case INVOKE_FUNC: case DISPATCH_CONSTRUCT: if(V_VT(&numv) == VT_NULL) hres = create_error(ctx, constr, NULL, msg, &err); else hres = create_error(ctx, constr, &num, msg, &err); SysFreeString(msg); if(FAILED(hres)) return hres; if(retv) { V_VT(retv) = VT_DISPATCH; V_DISPATCH(retv) = (IDispatch*)_IDispatchEx_(err); } else jsdisp_release(err); return S_OK; default: FIXME("unimplemented flags %x\n", flags); return E_NOTIMPL; } }
wchar_t *Variant2CWString(VARIANT *result){ switch(V_VT(result)){ case VT_EMPTY: return L"empty"; break; case VT_NULL: return L"null"; break; case VT_I2: // short return Number2String((long)V_I2(result)); break; case VT_I4: // long return Number2String((long)V_I4(result)); break; case VT_R4: // float return Double2String(V_R4(result)); break; case VT_R8: // double return Double2String(V_R8(result)); break; case VT_BOOL: //(True -1,False 0) return (V_BOOL(result) ? L"True" : L"False"); break; case VT_BSTR: return (wchar_t*)(V_BSTR(result)); break; case VT_DATE: return Date2String( V_DATE(result)); break; } }
STDMETHODIMP CAsdkSquareWrapper::SetElementValue( /* [in] */ DISPID dispID, /* [in] */ DWORD dwCookie, /* [in] */ VARIANT VarIn) { AcAxDocLock docLock(m_objRef.objectId(), AcAxDocLock::kNormal); if(docLock.lockStatus() != Acad::eOk && docLock.lockStatus() != Acad::eNoDatabase) return E_ACCESSDENIED; AcAxObjectRefPtr<AsdkSquare> pSq(&m_objRef, AcDb::kForRead); if (pSq.openStatus() != Acad::eOk) return E_ACCESSDENIED; if (dispID == DISPID_CENTERPOINT) { AcGePoint3d acgePt; pSq->squareCenter(acgePt); AcAxPoint3d acaxPt(acgePt); acaxPt[dwCookie] = V_R8(&VarIn); pSq->upgradeOpen(); pSq->setSquareCenter(acaxPt); Fire_Notification(DISPID_CENTERPOINT); } return S_OK; }
/** Turn a variant into an S object with a special class such as COMDate or COMCurrency which is simply an extension of numeric. */ SEXP numberFromVariant(VARIANT *var, VARTYPE type) { SEXP ans; SEXP klass; const char *tmpName = NULL; switch(type) { case VT_CY: tmpName = "COMCurrency"; break; case VT_DATE: tmpName = (char *) "COMDate"; break; case VT_HRESULT: tmpName = (char *) "HResult"; break; case VT_DECIMAL: tmpName = (char *) "COMDecimal"; break; default: PROBLEM "numberFromVariant called with unsupported variant type." ERROR; } PROTECT(klass = MAKE_CLASS(tmpName)); PROTECT(ans = NEW(klass)); ans = R_do_slot_assign(ans, mkString(".Data"), R_scalarReal(V_R8(var))); // SET_SLOT(ans, Rf_install(".Data"), R_scalarReal(V_R8(var))); UNPROTECT(2); return(ans); }
static HRESULT var2str(const VARIANT *p, nsAString *nsstr) { BSTR str; BOOL ret; HRESULT hres; switch(V_VT(p)) { case VT_BSTR: return nsAString_Init(nsstr, V_BSTR(p))? S_OK : E_OUTOFMEMORY; case VT_R8: hres = VarBstrFromR8(V_R8(p), 0, 0, &str); break; case VT_R4: hres = VarBstrFromR4(V_R4(p), 0, 0, &str); break; case VT_I4: hres = VarBstrFromI4(V_I4(p), 0, 0, &str); break; default: FIXME("unsupported arg %s\n", debugstr_variant(p)); return E_NOTIMPL; } if (FAILED(hres)) return hres; ret = nsAString_Init(nsstr, str); SysFreeString(str); return ret ? S_OK : E_OUTOFMEMORY; }
/* ECMA-262 3rd Edition 9.4 */ HRESULT to_integer(script_ctx_t *ctx, VARIANT *v, jsexcept_t *ei, VARIANT *ret) { VARIANT num; HRESULT hres; hres = to_number(ctx, v, ei, &num); if(FAILED(hres)) return hres; if(V_VT(&num) == VT_I4) *ret = num; else num_set_val(ret, V_R8(&num) >= 0.0 ? floor(V_R8(&num)) : -floor(-V_R8(&num))); return S_OK; }
/* ECMA-262 3rd Edition 9.2 */ HRESULT to_boolean(VARIANT *v, VARIANT_BOOL *b) { switch(V_VT(v)) { case VT_EMPTY: case VT_NULL: *b = VARIANT_FALSE; break; case VT_I4: *b = V_I4(v) ? VARIANT_TRUE : VARIANT_FALSE; break; case VT_R8: *b = V_R8(v) ? VARIANT_TRUE : VARIANT_FALSE; break; case VT_BSTR: *b = V_BSTR(v) && *V_BSTR(v) ? VARIANT_TRUE : VARIANT_FALSE; break; case VT_DISPATCH: *b = V_DISPATCH(v) ? VARIANT_TRUE : VARIANT_FALSE; break; case VT_BOOL: *b = V_BOOL(v); break; default: FIXME("unimplemented for vt %d\n", V_VT(v)); return E_NOTIMPL; } return S_OK; }
HRESULT double_to_string(double n, jsstr_t **str) { const WCHAR InfinityW[] = {'-','I','n','f','i','n','i','t','y',0}; if(isnan(n)) { *str = jsstr_nan(); }else if(isinf(n)) { *str = jsstr_alloc(n<0 ? InfinityW : InfinityW+1); }else if(is_int32(n)) { *str = int_to_string(n); }else { VARIANT strv, v; HRESULT hres; /* FIXME: Don't use VariantChangeTypeEx */ V_VT(&v) = VT_R8; V_R8(&v) = n; V_VT(&strv) = VT_EMPTY; hres = VariantChangeTypeEx(&strv, &v, MAKELCID(MAKELANGID(LANG_ENGLISH,SUBLANG_ENGLISH_US),SORT_DEFAULT), 0, VT_BSTR); if(FAILED(hres)) return hres; *str = jsstr_alloc(V_BSTR(&strv)); SysFreeString(V_BSTR(&strv)); } return *str ? S_OK : E_OUTOFMEMORY; }
static const char *debugstr_variant(const VARIANT *v) { if(!v) return "(null)"; switch(V_VT(v)) { case VT_EMPTY: return "{VT_EMPTY}"; case VT_NULL: return "{VT_NULL}"; case VT_I4: return wine_dbg_sprintf("{VT_I4: %d}", V_I4(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)); case VT_UNKNOWN: return wine_dbg_sprintf("{VT_UNKNOWN: %p}", V_UNKNOWN(v)); case VT_UINT: return wine_dbg_sprintf("{VT_UINT: %u}", V_UINT(v)); case VT_BSTR|VT_BYREF: return wine_dbg_sprintf("{VT_BSTR|VT_BYREF: ptr %p, data %s}", V_BSTRREF(v), debugstr_w(V_BSTRREF(v) ? *V_BSTRREF(v) : NULL)); default: return wine_dbg_sprintf("{vt %d}", V_VT(v)); } }
const char *debugstr_variant(const VARIANT *v) { if (!v) return "(null)"; 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_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_ERROR: return wine_dbg_sprintf("{VT_ERROR: %08x}", V_ERROR(v)); case VT_BOOL: return wine_dbg_sprintf("{VT_BOOL: %x}", V_BOOL(v)); case VT_UINT: return wine_dbg_sprintf("{VT_UINT: %u}", V_UINT(v)); default: return wine_dbg_sprintf("{vt %d}", V_VT(v)); } }
//+--------------------------------------------------------------------------- // // Function: CVarToVARIANTARG // // Synopsis: Converts a C-language variable to a VARIANT. // // Arguments: [pv] -- Pointer to C-language variable. // [vt] -- Type of C-language variable. // [pvarg] -- Resulting VARIANT. Must be initialized by caller. // Any contents will be freed. // // Modifies: [pvarg] // // History: 2-23-94 adams Created // // Notes: Supports all variant pointer types, VT_UI2, VT_I2, VT_UI4, // VT_I4, VT_R4, VT_R8, VT_ERROR. // //---------------------------------------------------------------------------- void CVarToVARIANTARG(void* pv, VARTYPE vt, VARIANTARG* pvarg) { Assert(pv); Assert(pvarg); VariantClear(pvarg); V_VT(pvarg) = vt; if(V_ISBYREF(pvarg)) { // Use a supported pointer type for derefencing. vt = VT_UNKNOWN; } switch(vt) { case VT_BOOL: // convert TRUE to VT_TRUE Assert(*(BOOL*)pv==1 || *(BOOL*)pv==0); V_BOOL(pvarg) = VARIANT_BOOL(-*(BOOL*)pv); break; case VT_I2: V_I2(pvarg) = *(short*)pv; break; case VT_ERROR: case VT_I4: V_I4(pvarg) = *(long*)pv; break; case VT_R4: V_R4(pvarg) = *(float*)pv; break; case VT_R8: V_R8(pvarg) = *(double*)pv; break; case VT_CY: V_CY(pvarg) = *(CY*)pv; break; // All Pointer types. case VT_PTR: case VT_BSTR: case VT_LPSTR: case VT_LPWSTR: case VT_DISPATCH: case VT_UNKNOWN: V_BYREF(pvarg) = *(void**)pv; break; default: Assert(FALSE && "Unknown type."); break; } }
HRESULT variant_to_jsval(VARIANT *var, jsval_t *r) { switch(V_VT(var)) { case VT_EMPTY: *r = jsval_undefined(); return S_OK; case VT_NULL: *r = jsval_null(); return S_OK; case VT_BOOL: *r = jsval_bool(V_BOOL(var)); return S_OK; case VT_I4: *r = jsval_number(V_I4(var)); return S_OK; case VT_R8: *r = jsval_number(V_R8(var)); return S_OK; case VT_BSTR: { jsstr_t *str; str = jsstr_alloc_len(V_BSTR(var), SysStringLen(V_BSTR(var))); if(!str) return E_OUTOFMEMORY; if(!V_BSTR(var)) str->length_flags |= JSSTR_FLAG_NULLBSTR; *r = jsval_string(str); return S_OK; } case VT_DISPATCH: { if(V_DISPATCH(var)) IDispatch_AddRef(V_DISPATCH(var)); *r = jsval_disp(V_DISPATCH(var)); return S_OK; } case VT_I2: *r = jsval_number(V_I2(var)); return S_OK; case VT_INT: *r = jsval_number(V_INT(var)); return S_OK; case VT_UNKNOWN: if(V_UNKNOWN(var)) { IDispatch *disp; HRESULT hres; hres = IUnknown_QueryInterface(V_UNKNOWN(var), &IID_IDispatch, (void**)&disp); if(SUCCEEDED(hres)) { *r = jsval_disp(disp); return S_OK; } } /* fall through */ default: return jsval_variant(r, var); } }
JNIEXPORT void JNICALL Java_com_tangram_Variant_putVariantDouble(JNIEnv *env, jobject _this, jdouble d) { VARIANT *v = extractVariant(env, _this); if (v) { VariantClear(v); // whatever was there before V_VT(v) = VT_R8; V_R8(v) = (double)d; } }
HRESULT jsval_to_variant(jsval_t val, VARIANT *retv) { switch(jsval_type(val)) { case JSV_UNDEFINED: V_VT(retv) = VT_EMPTY; return S_OK; case JSV_NULL: V_VT(retv) = VT_NULL; return S_OK; case JSV_OBJECT: V_VT(retv) = VT_DISPATCH; if(get_object(val)) IDispatch_AddRef(get_object(val)); V_DISPATCH(retv) = get_object(val); return S_OK; case JSV_STRING: { jsstr_t *str = get_string(val); V_VT(retv) = VT_BSTR; if(str->length_flags & JSSTR_FLAG_NULLBSTR) { V_BSTR(retv) = NULL; } else { V_BSTR(retv) = SysAllocStringLen(NULL, jsstr_length(str)); if(V_BSTR(retv)) jsstr_flush(str, V_BSTR(retv)); else return E_OUTOFMEMORY; } return S_OK; } case JSV_NUMBER: { double n = get_number(val); if(is_int32(n)) { V_VT(retv) = VT_I4; V_I4(retv) = n; } else { V_VT(retv) = VT_R8; V_R8(retv) = n; } return S_OK; } case JSV_BOOL: V_VT(retv) = VT_BOOL; V_BOOL(retv) = get_bool(val) ? VARIANT_TRUE : VARIANT_FALSE; return S_OK; case JSV_VARIANT: V_VT(retv) = VT_EMPTY; return VariantCopy(retv, get_variant(val)); } assert(0); return E_FAIL; }
/* ECMA-262 3rd Edition 9.6 */ HRESULT to_uint32(script_ctx_t *ctx, VARIANT *v, jsexcept_t *ei, DWORD *ret) { VARIANT num; HRESULT hres; hres = to_number(ctx, v, ei, &num); if(FAILED(hres)) return hres; *ret = V_VT(&num) == VT_I4 ? V_I4(&num) : (DWORD)V_R8(&num); return S_OK; }
/** * Returns the value of this Variant as a double if it is of that type. * Otherwise it will return null (no conversion done) */ JNIEXPORT jdouble JNICALL Java_com_tangram_Variant_getVariantDouble (JNIEnv *env, jobject _this) { VARIANT *v = extractVariant(env, _this); if (v) { if (V_VT(v) != VT_R8) { return NULL; } return (jdouble)V_R8(v); } return NULL; }
HRESULT create_math(script_ctx_t *ctx, jsdisp_t **ret) { jsdisp_t *math; unsigned i; VARIANT v; HRESULT hres; struct { const WCHAR *name; DOUBLE val; }constants[] = { {EW, M_E}, /* ECMA-262 3rd Edition 15.8.1.1 */ {LN10W, M_LN10}, /* ECMA-262 3rd Edition 15.8.1.2 */ {LN2W, M_LN2}, /* ECMA-262 3rd Edition 15.8.1.3 */ {LOG2EW, M_LOG2E}, /* ECMA-262 3rd Edition 15.8.1.4 */ {LOG10EW, M_LOG10E}, /* ECMA-262 3rd Edition 15.8.1.5 */ {PIW, M_PI}, /* ECMA-262 3rd Edition 15.8.1.6 */ {SQRT1_2W, M_SQRT1_2}, /* ECMA-262 3rd Edition 15.8.1.7 */ {SQRT2W, M_SQRT2}, /* ECMA-262 3rd Edition 15.8.1.8 */ }; math = heap_alloc_zero(sizeof(jsdisp_t)); if(!math) return E_OUTOFMEMORY; hres = init_dispex_from_constr(math, ctx, &Math_info, ctx->object_constr); if(FAILED(hres)) { heap_free(math); return hres; } V_VT(&v) = VT_R8; for(i=0; i < sizeof(constants)/sizeof(*constants); i++) { V_R8(&v) = constants[i].val; hres = jsdisp_propput_const(math, constants[i].name, &v); if(FAILED(hres)) { jsdisp_release(math); return hres; } } *ret = math; return S_OK; }
const char *debugstr_variant(const VARIANT *v) { switch(V_VT(v)) { case VT_EMPTY: return wine_dbg_sprintf("{VT_EMPTY}"); case VT_NULL: return wine_dbg_sprintf("{VT_NULL}"); case VT_I4: return wine_dbg_sprintf("{VT_I4: %d}", V_I4(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)); } }
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); }
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; }
/* ECMA-262 3rd Edition 15.7.4.2 */ static HRESULT Number_toString(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, DISPPARAMS *dp, VARIANT *retv, jsexcept_t *ei, IServiceProvider *sp) { NumberInstance *number; INT radix = 10; DOUBLE val; BSTR str; HRESULT hres; TRACE("\n"); if(!(number = number_this(jsthis))) return throw_type_error(ctx, ei, IDS_NOT_NUM, NULL); if(arg_cnt(dp)) { hres = to_int32(ctx, get_arg(dp, 0), ei, &radix); if(FAILED(hres)) return hres; if(radix<2 || radix>36) return throw_type_error(ctx, ei, IDS_INVALID_CALL_ARG, NULL); } if(V_VT(&number->num) == VT_I4) val = V_I4(&number->num); else val = V_R8(&number->num); if(radix==10 || isnan(val) || isinf(val)) { hres = to_string(ctx, &number->num, ei, &str); if(FAILED(hres)) return hres; } else { INT idx = 0; DOUBLE integ, frac, log_radix = 0; WCHAR buf[NUMBER_TOSTRING_BUF_SIZE+16]; BOOL exp = FALSE; if(val<0) { val = -val; buf[idx++] = '-'; } while(1) { integ = floor(val); frac = val-integ; if(integ == 0) buf[idx++] = '0'; while(integ>=1 && idx<NUMBER_TOSTRING_BUF_SIZE) { buf[idx] = fmod(integ, radix); if(buf[idx]<10) buf[idx] += '0'; else buf[idx] += 'a'-10; integ /= radix; idx++; } if(idx<NUMBER_TOSTRING_BUF_SIZE) { INT beg = buf[0]=='-'?1:0; INT end = idx-1; WCHAR wch; while(end > beg) { wch = buf[beg]; buf[beg++] = buf[end]; buf[end--] = wch; } } if(idx != NUMBER_TOSTRING_BUF_SIZE) buf[idx++] = '.'; while(frac>0 && idx<NUMBER_TOSTRING_BUF_SIZE) { frac *= radix; buf[idx] = fmod(frac, radix); frac -= buf[idx]; if(buf[idx]<10) buf[idx] += '0'; else buf[idx] += 'a'-10; idx++; } if(idx==NUMBER_TOSTRING_BUF_SIZE && !exp) { exp = TRUE; idx = (buf[0]=='-') ? 1 : 0; log_radix = floor(log(val)/log(radix)); val *= pow(radix, -log_radix); continue; } break; } while(buf[idx-1] == '0') idx--; if(buf[idx-1] == '.') idx--; if(exp) { if(log_radix==0) buf[idx++] = '\0'; else { static const WCHAR formatW[] = {'(','e','%','c','%','d',')',0}; WCHAR ch; if(log_radix<0) { log_radix = -log_radix; ch = '-'; } else ch = '+'; sprintfW(&buf[idx], formatW, ch, (int)log_radix); } } else buf[idx] = '\0'; str = SysAllocString(buf); if(!str) return E_OUTOFMEMORY; } if(retv) { V_VT(retv) = VT_BSTR; V_BSTR(retv) = str; }else { SysFreeString(str); } return S_OK; }
HRESULT VariantChangeTypeSpecial(VARIANT* pvargDest, VARIANT* pVArg, VARTYPE vt, IServiceProvider* pSrvProvider/*=NULL*/, DWORD dwFlags/*=0*/) { HRESULT hr; IVariantChangeType* pVarChangeType = NULL; if(pSrvProvider) { hr = pSrvProvider->QueryService(SID_VariantConversion, IID_IVariantChangeType, (void**)&pVarChangeType); if(hr) { goto OldWay; } // Use script engine conversion routine. hr = pVarChangeType->ChangeType(pvargDest, pVArg, 0, vt); if(!hr) { goto Cleanup; // ChangeType suceeded we're done... } } // Fall back to our tried & trusted type coercions OldWay: hr = S_OK; if(vt==VT_BSTR && V_VT(pVArg)==VT_NULL) { // Converting a NULL to BSTR V_VT(pvargDest) = VT_BSTR; hr = FormsAllocString(_T("null"), &V_BSTR(pvargDest)); goto Cleanup; } else if(vt==VT_BSTR && V_VT(pVArg)==VT_EMPTY) { // Converting "undefined" to BSTR V_VT(pvargDest) = VT_BSTR; hr = FormsAllocString(_T("undefined"), &V_BSTR(pvargDest)); goto Cleanup; } else if(vt==VT_BOOL && V_VT(pVArg)==VT_BSTR) { // Converting from BSTR to BOOL // To match Navigator compatibility empty strings implies false when // assigned to a boolean type any other string implies true. V_VT(pvargDest) = VT_BOOL; V_BOOL(pvargDest) = FormsStringLen(V_BSTR(pVArg))==0 ? VARIANT_FALSE : VARIANT_TRUE; goto Cleanup; } else if(V_VT(pVArg)==VT_BOOL && vt==VT_BSTR) { // Converting from BOOL to BSTR // To match Nav we either get "true" or "false" V_VT(pvargDest) = VT_BSTR; hr = FormsAllocString( V_BOOL(pVArg)==VARIANT_TRUE?_T("true"):_T("false"), &V_BSTR(pvargDest)); goto Cleanup; } // If we're converting R4 or R8 to a string then we need special handling to // map Nan and +/-Inf. else if(vt==VT_BSTR && (V_VT(pVArg)==VT_R8||V_VT(pVArg)==VT_R4)) { double dblValue = V_VT(pVArg)==VT_R8 ? V_R8(pVArg) : (double)(V_R4(pVArg)); // Infinity or NAN? if(!isFinite(dblValue)) { if(isNAN(dblValue)) { // NAN hr = FormsAllocStringW(_T("NaN"), &(V_BSTR(pvargDest))); } else { // Infinity hr = FormsAllocStringW((dblValue<0)?_T("-Infinity"):_T("Infinity"), &(V_BSTR(pvargDest))); } } else { goto DefaultConvert; } // Any error from allocating string? if(hr) { goto Cleanup; } V_VT(pvargDest) = vt; goto Cleanup; } DefaultConvert: // Default VariantChangeTypeEx. // VARIANT_NOUSEROVERRIDE flag is undocumented flag that tells OLEAUT to convert to the lcid // given. Without it the conversion is done to user localeid hr = VariantChangeTypeEx(pvargDest, pVArg, LCID_SCRIPTING, dwFlags|VARIANT_NOUSEROVERRIDE, vt); if(hr == DISP_E_TYPEMISMATCH) { if(V_VT(pVArg) == VT_NULL) { hr = S_OK; switch(vt) { case VT_BOOL: V_BOOL(pvargDest) = VARIANT_FALSE; V_VT(pvargDest) = VT_BOOL; break; // For NS compatability - NS treats NULL args as 0 default: V_I4(pvargDest)=0; break; } } else if(V_VT(pVArg) == VT_DISPATCH) { // Nav compatability - return the string [object] or null V_VT(pvargDest) = VT_BSTR; hr = FormsAllocString((V_DISPATCH(pVArg))?_T("[object]"):_T("null"), &V_BSTR(pvargDest)); } else if(V_VT(pVArg)==VT_BSTR && (V_BSTR(pVArg) && ((V_BSTR(pVArg))[0]==_T('\0')) ||!V_BSTR(pVArg)) && (vt==VT_I4 || vt==VT_I2 || vt==VT_UI2||vt==VT_UI4 || vt==VT_I8||vt==VT_UI8 || vt==VT_INT || vt==VT_UINT)) { // Converting empty string to integer => Zero hr = S_OK; V_VT(pvargDest) = vt; V_I4(pvargDest) = 0; goto Cleanup; } } else if(hr==DISP_E_OVERFLOW && vt==VT_I4 && (V_VT(pVArg)==VT_R8 || V_VT(pVArg)==VT_R4)) { // Nav compatability - return MAXLONG on overflow V_VT(pvargDest) = VT_I4; V_I4(pvargDest) = MAXLONG; hr = S_OK; goto Cleanup; } // To match Navigator change any scientific notation E to e. if(!hr && (vt==VT_BSTR && (V_VT(pVArg)==VT_R8 || V_VT(pVArg)==VT_R4))) { TCHAR* pENotation; pENotation = _tcschr(V_BSTR(pvargDest), _T('E')); if(pENotation) { *pENotation = _T('e'); } } Cleanup: ReleaseInterface(pVarChangeType); RRETURN(hr); }
SEXP R_convertDCOMObjectToR(VARIANT *var) { SEXP ans = R_NilValue; VARTYPE type = V_VT(var); #if defined(RDCOM_VERBOSE) && RDCOM_VERBOSE errorLog("Converting VARIANT to R %d\n", V_VT(var)); #endif if(V_ISARRAY(var)) { #if defined(RDCOM_VERBOSE) && RDCOM_VERBOSE errorLog("Finishing convertDCOMObjectToR - convert array\n"); #endif return(convertArrayToR(var)); } else if(V_VT(var) == VT_DISPATCH || (V_ISBYREF(var) && ((V_VT(var) & (~ VT_BYREF)) == VT_DISPATCH)) ) { IDispatch *ptr; if(V_ISBYREF(var)) { #if defined(RDCOM_VERBOSE) && RDCOM_VERBOSE errorLog("BYREF and DISPATCH in convertDCOMObjectToR\n"); #endif IDispatch **tmp = V_DISPATCHREF(var); if(!tmp) return(ans); ptr = *tmp; } else ptr = V_DISPATCH(var); //xxx if(ptr) ptr->AddRef(); ans = R_createRCOMUnknownObject((void*) ptr, "COMIDispatch"); #if defined(RDCOM_VERBOSE) && RDCOM_VERBOSE errorLog("Finished convertDCOMObjectToR COMIDispatch\n"); #endif return(ans); } if(V_ISBYREF(var)) { VARTYPE rtype = type & (~ VT_BYREF); #if defined(RDCOM_VERBOSE) && RDCOM_VERBOSE errorLog("ISBYREF() in convertDCOMObjectToR: ref type %d\n", rtype); #endif if(rtype == VT_BSTR) { BSTR *tmp; const char *ptr = ""; #if defined(RDCOM_VERBOSE) && RDCOM_VERBOSE errorLog("BYREF and BSTR convertDCOMObjectToR (scalar string)\n"); #endif tmp = V_BSTRREF(var); if(tmp) ptr = FromBstr(*tmp); ans = R_scalarString(ptr); return(ans); } else if(rtype == VT_BOOL || rtype == VT_I4 || rtype == VT_R8){ return(createVariantRef(var, rtype)); } else { fprintf(stderr, "Unhandled by-reference conversion type %d\n", V_VT(var));fflush(stderr); return(R_NilValue); } } switch(type) { case VT_BOOL: ans = R_scalarLogical( (Rboolean) (V_BOOL(var) ? TRUE : FALSE)); break; case VT_UI1: case VT_UI2: case VT_UI4: case VT_UINT: VariantChangeType(var, var, 0, VT_I4); ans = R_scalarReal((double) V_I4(var)); break; case VT_I1: case VT_I2: case VT_I4: case VT_INT: VariantChangeType(var, var, 0, VT_I4); ans = R_scalarInteger(V_I4(var)); break; case VT_R4: case VT_R8: case VT_I8: VariantChangeType(var, var, 0, VT_R8); ans = R_scalarReal(V_R8(var)); break; case VT_CY: case VT_DATE: case VT_HRESULT: case VT_DECIMAL: VariantChangeType(var, var, 0, VT_R8); ans = numberFromVariant(var, type); break; case VT_BSTR: { char *ptr = FromBstr(V_BSTR(var)); ans = R_scalarString(ptr); } break; case VT_UNKNOWN: { IUnknown *ptr = V_UNKNOWN(var); //xxx if(ptr) ptr->AddRef(); ans = R_createRCOMUnknownObject((void**) ptr, "COMUnknown"); } break; case VT_EMPTY: case VT_NULL: case VT_VOID: return(R_NilValue); break; /*XXX Need to fill these in */ case VT_RECORD: case VT_FILETIME: case VT_BLOB: case VT_STREAM: case VT_STORAGE: case VT_STREAMED_OBJECT: /* case LPSTR: */ case VT_LPWSTR: case VT_PTR: case VT_ERROR: case VT_VARIANT: case VT_CARRAY: case VT_USERDEFINED: default: fprintf(stderr, "Unhandled conversion type %d\n", V_VT(var));fflush(stderr); //XXX this consumes the variant. So the variant clearance in Invoke() does it again! ans = createRVariantObject(var, V_VT(var)); } #if defined(RDCOM_VERBOSE) && RDCOM_VERBOSE errorLog("Finished convertDCOMObjectToR\n"); #endif return(ans); }
HRESULT R_convertRObjectToDCOM(SEXP obj, VARIANT *var) { HRESULT status; int type = R_typeof(obj); if(!var) return(S_FALSE); #ifdef RDCOM_VERBOSE errorLog("Type of argument %d\n", type); #endif if(type == EXTPTRSXP && EXTPTR_TAG(obj) == Rf_install("R_VARIANT")) { VARIANT *tmp; tmp = (VARIANT *) R_ExternalPtrAddr(obj); if(tmp) { //XXX VariantCopy(var, tmp); return(S_OK); } } if(ISCOMIDispatch(obj)) { IDispatch *ptr; ptr = (IDispatch *) derefRIDispatch(obj); V_VT(var) = VT_DISPATCH; V_DISPATCH(var) = ptr; //XX ptr->AddRef(); return(S_OK); } if(ISSInstanceOf(obj, "COMDate")) { double val; val = NUMERIC_DATA(GET_SLOT(obj, Rf_install(".Data")))[0]; V_VT(var) = VT_DATE; V_DATE(var) = val; return(S_OK); } else if(ISSInstanceOf(obj, "COMCurrency")) { double val; val = NUMERIC_DATA(GET_SLOT(obj, Rf_install(".Data")))[0]; V_VT(var) = VT_R8; V_R8(var) = val; VariantChangeType(var, var, 0, VT_CY); return(S_OK); } else if(ISSInstanceOf(obj, "COMDecimal")) { double val; val = NUMERIC_DATA(GET_SLOT(obj, Rf_install(".Data")))[0]; V_VT(var) = VT_R8; V_R8(var) = val; VariantChangeType(var, var, 0, VT_DECIMAL); return(S_OK); } /* We have a complex object and we are not going to try to convert it directly but instead create an COM server object to represent it to the outside world. */ if((type == VECSXP && Rf_length(GET_NAMES(obj))) || Rf_length(GET_CLASS(obj)) > 0 || isMatrix(obj)) { status = createGenericCOMObject(obj, var); if(status == S_OK) return(S_OK); } if(Rf_length(obj) == 0) { V_VT(var) = VT_VOID; return(S_OK); } if(type == VECSXP || Rf_length(obj) > 1) { createRDCOMArray(obj, var); return(S_OK); } switch(type) { case STRSXP: V_VT(var) = VT_BSTR; V_BSTR(var) = AsBstr(getRString(obj, 0)); break; case INTSXP: V_VT(var) = VT_I4; V_I4(var) = R_integerScalarValue(obj, 0); break; case REALSXP: V_VT(var) = VT_R8; V_R8(var) = R_realScalarValue(obj, 0); break; case LGLSXP: V_VT(var) = VT_BOOL; V_BOOL(var) = R_logicalScalarValue(obj, 0) ? VARIANT_TRUE : VARIANT_FALSE; break; case VECSXP: break; } return(S_OK); }
//+--------------------------------------------------------------------------- // // Function: VARIANTARGToCVar // // Synopsis: Converts a VARIANT to a C-language variable. // // Arguments: [pvarg] -- Variant to convert. // [pfAlloc] -- BSTR allocated during conversion caller is // now owner of this BSTR or IUnknown or IDispatch // object allocated needs to be released. // [vt] -- Type to convert to. // [pv] -- Location to place C-language variable. // // Modifies: [pv]. // // Returns: HRESULT. // // History: 2-23-94 adams Created // // Notes: Supports all variant pointer types, VT_I2, VT_I4, VT_R4, // VT_R8, VT_ERROR. //---------------------------------------------------------------------------- HRESULT VARIANTARGToCVar(VARIANT* pvarg, BOOL* pfAlloc, VARTYPE vt, void* pv, IServiceProvider* pSrvProvider, WORD wMaxstrlen) { HRESULT hr = S_OK; VARIANTARG* pVArgCopy = pvarg; VARIANTARG vargNew; // variant of new type BOOL fAlloc; Assert(pvarg); Assert(pv); if(!pfAlloc) { pfAlloc = &fAlloc; } Assert((vt&~VT_TYPEMASK) == 0 || (vt&~VT_TYPEMASK)==VT_BYREF); // Assume no allocations yet. *pfAlloc = FALSE; if(vt & VT_BYREF) { // If the parameter is a variant pointer then everything is acceptable. if((vt&VT_TYPEMASK) == VT_VARIANT) { switch(V_VT(pvarg)) { case VT_VARIANT|VT_BYREF: hr = ClipVarString(pvarg->pvarVal, *(VARIANT**)pv, pfAlloc, wMaxstrlen); break; default: hr = ClipVarString(pvarg, *(VARIANT**)pv, pfAlloc, wMaxstrlen); break; } if(hr == S_FALSE) { hr = S_OK; *(PVOID*)pv = (PVOID)pvarg; } goto Cleanup; } if((V_VT(pvarg)&VT_TYPEMASK) != (vt&VT_TYPEMASK)) { hr = DISP_E_TYPEMISMATCH; goto Cleanup; } // Type of both original and destination or same type (however, original // may not be a byref only the original. if(V_ISBYREF(pvarg)) { // Destination and original are byref and same type just copy pointer. *(PVOID*)pv = V_BYREF(pvarg); } else { // Convert original to byref. switch(vt & VT_TYPEMASK) { case VT_BOOL: *(PVOID*)pv = (PVOID)&V_BOOL(pvarg); break; case VT_I2: *(PVOID*)pv = (PVOID)&V_I2(pvarg); break; case VT_ERROR: case VT_I4: *(PVOID*)pv = (PVOID)&V_I4(pvarg); break; case VT_R4: *(PVOID*)pv = (PVOID)&V_R4(pvarg); break; case VT_R8: *(PVOID*)pv = (PVOID)&V_R8(pvarg); break; case VT_CY: *(PVOID*)pv = (PVOID)&V_CY(pvarg); break; // All pointer types. case VT_PTR: case VT_BSTR: case VT_LPSTR: case VT_LPWSTR: case VT_DISPATCH: case VT_UNKNOWN: *(PVOID*)pv = (PVOID)&V_UNKNOWN(pvarg); break; case VT_VARIANT: Assert("Dead code: shudn't have gotten here!"); *(PVOID*)pv = (PVOID)pvarg; break; default: Assert(!"Unknown type in BYREF VARIANTARGToCVar().\n"); hr = DISP_E_TYPEMISMATCH; goto Cleanup; } } goto Cleanup; } // If the c style parameter is the same type as the VARIANT then we'll just // move the data. Also if the c style type is a VARIANT then there's // nothing to convert just copy the variant to the C parameter. else if((V_VT(pvarg)&(VT_TYPEMASK|VT_BYREF))!=vt && (vt!=VT_VARIANT)) { // If the request type isn't the same as the variant passed in then we // need to convert. VariantInit(&vargNew); pVArgCopy = &vargNew; hr = VariantChangeTypeSpecial(pVArgCopy, pvarg, vt,pSrvProvider); if(hr) { goto Cleanup; } *pfAlloc = (vt==VT_BSTR) || (vt==VT_UNKNOWN) || (vt==VT_DISPATCH); } // Move the variant data to C style data. switch(vt) { case VT_BOOL: // convert VT_TRUE and any other non-zero values to TRUE *(VARIANT_BOOL*)pv = V_BOOL(pVArgCopy); break; case VT_I2: *(short*)pv = V_I2(pVArgCopy); break; case VT_ERROR: case VT_I4: *(long*)pv = V_I4(pVArgCopy); break; case VT_R4: *(float*)pv = V_R4(pVArgCopy); break; case VT_R8: *(double*)pv = V_R8(pVArgCopy); break; case VT_CY: *(CY*)pv = V_CY(pVArgCopy); break; // All Pointer types. case VT_BSTR: if(wMaxstrlen && FormsStringLen(V_BSTR(pVArgCopy))>wMaxstrlen) { hr = FormsAllocStringLen(V_BSTR(pVArgCopy), wMaxstrlen, (BSTR*)pv); if(hr) { goto Cleanup; } if(*pfAlloc) { VariantClear(&vargNew); } else { *pfAlloc = TRUE; } goto Cleanup; } case VT_PTR: case VT_LPSTR: case VT_LPWSTR: case VT_DISPATCH: case VT_UNKNOWN: *(void**)pv = V_BYREF(pVArgCopy); break; case VT_VARIANT: hr = ClipVarString(pVArgCopy, (VARIANT*)pv, pfAlloc, wMaxstrlen); if(hr == S_FALSE) { hr = S_OK; // Copy entire variant to output parameter. *(VARIANT*)pv = *pVArgCopy; } break; default: Assert(FALSE && "Unknown type in VARIANTARGToCVar().\n"); hr = DISP_E_TYPEMISMATCH; break; } Cleanup: RRETURN(hr); }
//This is used to set the value for an element in a group. //The element is identified by the dwCookie parameter STDMETHODIMP CComPolygon::SetElementValue( /* [in] */ DISPID dispID, /* [in] */ DWORD dwCookie, /* [in] */ VARIANT VarIn) { if (dispID >= DISPID_NORMAL && dispID <= DISPID_STARTPOINT) { try { if (dwCookie>2) throw Acad::eInvalidInput; Acad::ErrorStatus es; AcAxObjectRefPtr<AsdkPoly> pPoly(&m_objRef,AcDb::kForWrite,Adesk::kTrue); if((es=pPoly.openStatus()) != Acad::eOk) throw es; AcAxPoint3d pt; AcAxPoint2d pt2d; if (dispID == DISPID_NORMAL) { pt = pPoly->normal(); //translate from wcs to ucs acdbEcs2Ucs(asDblArray(pt),asDblArray(pt),asDblArray(pPoly->normal()),Adesk::kTrue); } else { switch (dispID) { case DISPID_CENTER: pt2d = pPoly->center(); break; case DISPID_STARTPOINT: pt2d = pPoly->startPoint(); break; default: throw Acad::eInvalidInput; } pt.set(pt2d.x,pt2d.y,pPoly->elevation()); //translate from wcs to ucs acdbEcs2Ucs(asDblArray(pt),asDblArray(pt),asDblArray(pPoly->normal()),Adesk::kFalse); } pt[dwCookie] = V_R8(&VarIn); if (dispID == DISPID_NORMAL) { acdbUcs2Wcs(asDblArray(pt),asDblArray(pt),Adesk::kTrue); if ((es=pPoly->setNormal(pt.asVector()))!=Acad::eOk) throw es; }else { acdbUcs2Ecs(asDblArray(pt),asDblArray(pt),asDblArray(pPoly->normal()),Adesk::kFalse); pt2d.set(pt.x,pt.y); pPoly->setElevation(pt.z); if (dispID == DISPID_CENTER) if ((es=pPoly->setCenter(pt2d))!=Acad::eOk) throw es; if (dispID == DISPID_STARTPOINT) if ((es=pPoly->setStartPoint(pt2d))!=Acad::eOk) throw es; } Fire_Notification(dispID); } catch(const Acad::ErrorStatus) { return Error(L"Failed to open object",IID_IComPolygon,E_FAIL); } catch(const HRESULT hr) { return Error(L"Invalid argument.",IID_IComPolygon,hr); } } return S_OK; }
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; }
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; } } }
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; } } }