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)); } }
/* Only for VT_BSTR or VT_BSTR|VT_BYREF types */ static inline WCHAR *get_key_strptr(const VARIANT *key) { if (V_VT(key) == VT_BSTR) return V_BSTR(key); if (V_BSTRREF(key)) return *V_BSTRREF(key); return NULL; }
static unsigned long wire_extra_user_size(unsigned long *pFlags, unsigned long Start, VARIANT *pvar) { if (V_ISARRAY(pvar)) { if (V_ISBYREF(pvar)) return LPSAFEARRAY_UserSize(pFlags, Start, V_ARRAYREF(pvar)); else return LPSAFEARRAY_UserSize(pFlags, Start, &V_ARRAY(pvar)); } switch (V_VT(pvar)) { case VT_BSTR: return BSTR_UserSize(pFlags, Start, &V_BSTR(pvar)); case VT_BSTR | VT_BYREF: return BSTR_UserSize(pFlags, Start, V_BSTRREF(pvar)); case VT_VARIANT | VT_BYREF: return VARIANT_UserSize(pFlags, Start, V_VARIANTREF(pvar)); case VT_UNKNOWN: return Start + interface_variant_size(pFlags, &IID_IUnknown, pvar); case VT_DISPATCH: return Start + interface_variant_size(pFlags, &IID_IDispatch, pvar); case VT_RECORD: FIXME("wire-size record\n"); return Start; case VT_SAFEARRAY: case VT_SAFEARRAY | VT_BYREF: FIXME("wire-size safearray: shouldn't be marshaling this\n"); return Start; default: return Start; } }
static HRESULT WINAPI WebBrowser_Navigate2(IWebBrowser2 *iface, VARIANT *URL, VARIANT *Flags, VARIANT *TargetFrameName, VARIANT *PostData, VARIANT *Headers) { WebBrowser *This = impl_from_IWebBrowser2(iface); LPCWSTR url; TRACE("(%p)->(%s %s %s %s %s)\n", This, debugstr_variant(URL), debugstr_variant(Flags), debugstr_variant(TargetFrameName), debugstr_variant(PostData), debugstr_variant(Headers)); if(!This->client) return E_FAIL; if(!URL) return S_OK; switch (V_VT(URL)) { case VT_BSTR: url = V_BSTR(URL); break; case VT_BSTR|VT_BYREF: url = *V_BSTRREF(URL); break; default: FIXME("Unsupported V_VT(URL) %d\n", V_VT(URL)); return E_INVALIDARG; } return navigate_url(&This->doc_host, url, Flags, TargetFrameName, PostData, Headers); }
JNIEXPORT void JNICALL Java_com_tangram_Variant_release(JNIEnv *env, jobject _this) { jclass clazz = env->GetObjectClass(_this); jfieldID jf = env->GetFieldID(clazz, VARIANT_FLD, "J"); VARIANT *v = extractVariant(env, _this); if (v) { // fix byref leak if (V_VT(v) & VT_BYREF) // is this a reference { void *pMem = V_BSTRREF(v); // get allocated memory if (pMem) { if (V_VT(v) == (VT_BYREF | VT_BSTR)) { BSTR *pBstr = (BSTR*)pMem; if (*pBstr) SysFreeString(*pBstr);// release bstr } CoTaskMemFree(pMem); } } VariantClear(v); delete v; env->SetLongField(_this, jf, 0ll); } }
JNIEXPORT jstring JNICALL Java_com_tangram_Variant_getVariantStringRef(JNIEnv *env, jobject _this) { VARIANT *v = extractVariant(env, _this); if (v) { if (V_VT(v) != (VT_BSTR | VT_BYREF)) { return NULL; } BSTR *bs = V_BSTRREF(v); jstring js = env->NewString((jchar*)*bs, SysStringLen(*bs)); // SR cast SF 1689061 return js; } return NULL; }
// SF 1065533 added unicode support JNIEXPORT void JNICALL Java_com_tangram_Variant_putVariantStringRef(JNIEnv *env, jobject _this, jstring s) { VARIANT *v = extractVariant(env, _this); if (v) { VariantClear(v); // whatever was there before const jchar *cStr = env->GetStringChars(s, NULL); // SF 1314116 // DBeck: 2005-09-23: changed CComBSTR c-tor to accept // Unicode string (no terminating NULL) provided by GetStringChars const jsize numChars = env->GetStringLength(s); //CComBSTR bs(cStr); CComBSTR bs(numChars, (LPCOLESTR)cStr); // SR cast SF 1689061 BSTR *pbs = (BSTR *)CoTaskMemAlloc(sizeof(BSTR)); bs.CopyTo(pbs); V_VT(v) = VT_BSTR | VT_BYREF; V_BSTRREF(v) = pbs; env->ReleaseStringChars(s, cStr); } }
void WINAPI VARIANT_UserFree(unsigned long *pFlags, VARIANT *pvar) { VARTYPE vt = V_VT(pvar); PVOID ref = NULL; TRACE("(%lx,%p)\n", *pFlags, pvar); TRACE("vt=%04x\n", V_VT(pvar)); if (vt & VT_BYREF) ref = pvar->n1.n2.n3.byref; VariantClear(pvar); if (!ref) return; if(vt & VT_ARRAY) LPSAFEARRAY_UserFree(pFlags, V_ARRAYREF(pvar)); else { switch (vt) { case VT_BSTR | VT_BYREF: BSTR_UserFree(pFlags, V_BSTRREF(pvar)); break; case VT_VARIANT | VT_BYREF: VARIANT_UserFree(pFlags, V_VARIANTREF(pvar)); break; case VT_RECORD | VT_BYREF: FIXME("handle BRECORD by ref\n"); break; case VT_UNKNOWN | VT_BYREF: case VT_DISPATCH | VT_BYREF: IUnknown_Release(*V_UNKNOWNREF(pvar)); break; } } CoTaskMemFree(ref); }
unsigned char * WINAPI VARIANT_UserUnmarshal(unsigned long *pFlags, unsigned char *Buffer, VARIANT *pvar) { variant_wire_t *header; unsigned long type_size; int align; unsigned char *Pos; TRACE("(%lx,%p,%p)\n", *pFlags, Buffer, pvar); ALIGN_POINTER(Buffer, 7); VariantInit(pvar); header = (variant_wire_t *)Buffer; pvar->n1.n2.vt = header->vt; pvar->n1.n2.wReserved1 = header->wReserved1; pvar->n1.n2.wReserved2 = header->wReserved2; pvar->n1.n2.wReserved3 = header->wReserved3; Pos = (unsigned char*)(header + 1); type_size = get_type_size(pFlags, pvar); align = get_type_alignment(pFlags, pvar); ALIGN_POINTER(Pos, align); if(header->vt & VT_BYREF) { Pos += 4; pvar->n1.n2.n3.byref = CoTaskMemAlloc(type_size); memcpy(pvar->n1.n2.n3.byref, Pos, type_size); if((header->vt & VT_TYPEMASK) != VT_VARIANT) Pos += type_size; else Pos += 4; } else { if((header->vt & VT_TYPEMASK) == VT_DECIMAL) memcpy(pvar, Pos, type_size); else memcpy(&pvar->n1.n2.n3, Pos, type_size); Pos += type_size; } if(header->vt & VT_ARRAY) { if(header->vt & VT_BYREF) Pos = LPSAFEARRAY_UserUnmarshal(pFlags, Pos, V_ARRAYREF(pvar)); else Pos = LPSAFEARRAY_UserUnmarshal(pFlags, Pos, &V_ARRAY(pvar)); } else { switch (header->vt) { case VT_BSTR: V_BSTR(pvar) = NULL; Pos = BSTR_UserUnmarshal(pFlags, Pos, &V_BSTR(pvar)); break; case VT_BSTR | VT_BYREF: *V_BSTRREF(pvar) = NULL; Pos = BSTR_UserUnmarshal(pFlags, Pos, V_BSTRREF(pvar)); break; case VT_VARIANT | VT_BYREF: Pos = VARIANT_UserUnmarshal(pFlags, Pos, V_VARIANTREF(pvar)); break; case VT_DISPATCH | VT_BYREF: FIXME("handle DISPATCH by ref\n"); break; case VT_UNKNOWN: /* this should probably call WdtpInterfacePointer_UserUnmarshal in ole32.dll */ Pos = interface_variant_unmarshal(pFlags, Pos, &IID_IUnknown, pvar); break; case VT_DISPATCH: /* this should probably call WdtpInterfacePointer_UserUnmarshal in ole32.dll */ Pos = interface_variant_unmarshal(pFlags, Pos, &IID_IDispatch, pvar); break; case VT_RECORD: FIXME("handle BRECORD by val\n"); break; case VT_RECORD | VT_BYREF: FIXME("handle BRECORD by ref\n"); break; } } return Pos; }
unsigned char * WINAPI VARIANT_UserMarshal(unsigned long *pFlags, unsigned char *Buffer, VARIANT *pvar) { variant_wire_t *header; unsigned long type_size; int align; unsigned char *Pos; TRACE("(%lx,%p,%p)\n", *pFlags, Buffer, pvar); TRACE("vt=%04x\n", V_VT(pvar)); ALIGN_POINTER(Buffer, 7); header = (variant_wire_t *)Buffer; header->clSize = 0; /* fixed up at the end */ header->rpcReserverd = 0; header->vt = pvar->n1.n2.vt; header->wReserved1 = pvar->n1.n2.wReserved1; header->wReserved2 = pvar->n1.n2.wReserved2; header->wReserved3 = pvar->n1.n2.wReserved3; header->switch_is = pvar->n1.n2.vt; if(header->switch_is & VT_ARRAY) header->switch_is &= ~VT_TYPEMASK; Pos = (unsigned char*)(header + 1); type_size = get_type_size(pFlags, pvar); align = get_type_alignment(pFlags, pvar); ALIGN_POINTER(Pos, align); if(header->vt & VT_BYREF) { *(DWORD *)Pos = max(type_size, 4); Pos += 4; if((header->vt & VT_TYPEMASK) != VT_VARIANT) { memcpy(Pos, pvar->n1.n2.n3.byref, type_size); Pos += type_size; } else { *(DWORD*)Pos = 'U' | 's' << 8 | 'e' << 16 | 'r' << 24; Pos += 4; } } else { if((header->vt & VT_TYPEMASK) == VT_DECIMAL) memcpy(Pos, pvar, type_size); else memcpy(Pos, &pvar->n1.n2.n3, type_size); Pos += type_size; } if(header->vt & VT_ARRAY) { if(header->vt & VT_BYREF) Pos = LPSAFEARRAY_UserMarshal(pFlags, Pos, V_ARRAYREF(pvar)); else Pos = LPSAFEARRAY_UserMarshal(pFlags, Pos, &V_ARRAY(pvar)); } else { switch (header->vt) { case VT_BSTR: Pos = BSTR_UserMarshal(pFlags, Pos, &V_BSTR(pvar)); break; case VT_BSTR | VT_BYREF: Pos = BSTR_UserMarshal(pFlags, Pos, V_BSTRREF(pvar)); break; case VT_VARIANT | VT_BYREF: Pos = VARIANT_UserMarshal(pFlags, Pos, V_VARIANTREF(pvar)); break; case VT_DISPATCH | VT_BYREF: FIXME("handle DISPATCH by ref\n"); break; case VT_UNKNOWN: /* this should probably call WdtpInterfacePointer_UserMarshal in ole32.dll */ Pos = interface_variant_marshal(pFlags, Pos, &IID_IUnknown, pvar); break; case VT_DISPATCH: /* this should probably call WdtpInterfacePointer_UserMarshal in ole32.dll */ Pos = interface_variant_marshal(pFlags, Pos, &IID_IDispatch, pvar); break; case VT_RECORD: FIXME("handle BRECORD by val\n"); break; case VT_RECORD | VT_BYREF: FIXME("handle BRECORD by ref\n"); break; } } header->clSize = ((Pos - Buffer) + 7) >> 3; TRACE("marshalled size=%ld\n", header->clSize); return Pos; }
static void putOutVariant (Tcl_Interp *interp, VARIANT *pDest, TclObject &tclObject, const Type &type) { switch (type.vartype()) { case VT_BOOL: *V_BOOLREF(pDest) = tclObject.getBool() ? VARIANT_TRUE : VARIANT_FALSE; break; case VT_R4: *V_R4REF(pDest) = static_cast<float>(tclObject.getDouble()); break; case VT_R8: *V_R8REF(pDest) = tclObject.getDouble(); break; case VT_DISPATCH: case VT_UNKNOWN: case VT_USERDEFINED: { IUnknown *pUnknown; Tcl_Obj *pObj = tclObject; if (pObj->typePtr == &Extension::unknownPointerType) { pUnknown = static_cast<IUnknown *>(pObj->internalRep.otherValuePtr); } else { Reference *pRef = Extension::referenceHandles.find( interp, tclObject); pUnknown = (pRef == 0) ? 0 : pRef->unknown(); } *V_UNKNOWNREF(pDest) = pUnknown; // The COM rules say we must increment the reference count of // interface pointers returned from methods. if (pUnknown != 0) { pUnknown->AddRef(); } } break; case VT_BSTR: *V_BSTRREF(pDest) = tclObject.getBSTR(); break; case VT_VARIANT: { // Must increment reference count of interface pointers returned // from methods. tclObject.toVariant( V_VARIANTREF(pDest), Type::variant(), interp, true); } break; case VT_SAFEARRAY: if (*V_ARRAYREF(pDest) != 0) { SafeArrayDestroy(*V_ARRAYREF(pDest)); } *V_ARRAYREF(pDest) = tclObject.getSafeArray(type.elementType(), interp); break; default: *V_I4REF(pDest) = tclObject.getLong(); } }
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; } } }
void LaunchWord(CString sPathWord,CString sPathOutput){ BSTR param2 = sPathWord.AllocSysString();//SysAllocString(OLESTR("HKEY_LOCAL_MACHINE\\Software\\Microsoft\\Windows\\CurrentVersion\\App Paths\\IEXPLORE.EXE")); BSTR param1 = sPathOutput.AllocSysString();//SysAllocString(OLESTR("")); BSTR name1 = SysAllocString(OLESTR("PathWord")); BSTR name2 = SysAllocString(OLESTR("PathOutput")); AddArgumentCString(name1,0,param1); AddArgumentCString(name2,0,param2); VARIANTARG FAR rgvarg[2]; V_BSTRREF(&rgvarg[0]) = ¶m1; V_BSTRREF(&rgvarg[1]) = ¶m2; DISPPARAMS dpNoArgs = {g_aVargs, NULL, 2, 0}; VARIANT vResult; OLECHAR FAR* szFunction; //BSTR bstrTemp; // IDispatch pointers for Word's objects //IDispatch* pDispDocs; //Documents collection // DISPIDs DISPID dispid_Docs; //Documents property of Application //object //Initialize the COM libraries ::CoInitialize(NULL); // Create an instance of the Word application and obtain the // pointer to the application's IDispatch interface. CLSID clsid; CLSIDFromString(L"UtilsVB.clsLauncher", &clsid); IUnknown* pUnk; HRESULT hr = ::CoCreateInstance( clsid, NULL, CLSCTX_SERVER, IID_IUnknown, (void**) &pUnk); IDispatch* pDispApp; hr = pUnk->QueryInterface(IID_IDispatch, (void**)&pDispApp); // Get IDispatch* for the Documents collection object szFunction = OLESTR("Launcher"); hr = pDispApp->GetIDsOfNames (IID_NULL, &szFunction, 1, LOCALE_USER_DEFAULT, &dispid_Docs); unsigned int FAR uArgErr; hr = pDispApp->Invoke (dispid_Docs, IID_NULL, LOCALE_USER_DEFAULT, DISPATCH_METHOD, &dpNoArgs, &vResult, NULL, &uArgErr); //Execute Internet Explorer /* CString sPath; HINSTANCE hinstance=ShellExecute( AfxGetMainWnd( )->m_hWnd, //HWND hwnd, "open", //LPCTSTR lpVerb, CString(vResult.bstrVal),//"C:\\Archivos de programa\\Internet Explorer\\IEXPLORE.EXE",//"C:\\Archivos de programa\\Microsoft Office\\Office\\WINWORD.EXE",//LPCTSTR lpFile, sPath,//"\"file://C:\\2002\\DraftCable\\Src\\testfile.htm\"", //LPCTSTR lpParameters, NULL, //LPCTSTR lpDirectory, SW_SHOWNORMAL //INT nShowCmd ); */ ClearAllArgs(); pDispApp->Release(); pUnk->Release(); //... ::CoUninitialize(); }
//////////////////////////////////////////////////////// // CompareVariant // //////////////////////////////////////////////////////// LONG CompareVariant ( VARIANT *pVar1, //@parm [in]: Pointer to the variant in the consumer's buffer. VARIANT *pVar2, //@parm [in]: Pointer to the variant at the backend. BOOL fCaseSensitive ) { //Handle NULL cases... if(pVar1==NULL || pVar2==NULL) { if(pVar1 == pVar2) return TRUE; return FALSE; } // The variant has to be the same type if (V_VT(pVar1) != V_VT(pVar2)) return FALSE; // Return FALSE if vt is ORed with VT_RESERVED if (V_VT(pVar1) & VT_RESERVED) return FALSE; // Return TRUE is the vt is VT_EMPTY or VT_NULL if (V_VT(pVar1)==VT_EMPTY || V_VT(pVar1)==VT_NULL) return TRUE; switch(V_VT(pVar1)) { case VT_UI1: return V_UI1(pVar1) == V_UI1(pVar2); case VT_I2: return V_I2(pVar1) == V_I2(pVar2); case VT_I4: return V_I4(pVar1) == V_I4(pVar2); case VT_R4: return V_R4(pVar1) == V_R4(pVar2); case VT_R8: return V_R8(pVar1) == V_R8(pVar2); case VT_BOOL: return V_BOOL(pVar1) == V_BOOL(pVar2); case VT_ERROR: return V_ERROR(pVar1) == V_ERROR(pVar2); case VT_CY: return memcmp(&V_CY(pVar1), &V_CY(pVar2),8)==0; case VT_DATE: return V_DATE(pVar1) == V_DATE(pVar2); case VT_BSTR: if(fCaseSensitive) return wcscmp(V_BSTR(pVar1), V_BSTR(pVar2)); else return _wcsicmp(V_BSTR(pVar1), V_BSTR(pVar2)); // As we are not testing OLE object, return FALSE for VT_UNKNOWN case VT_UNKNOWN: return FALSE; // As we are not testing OLE object, return FALSE for VT_DISPATCH case VT_DISPATCH: return FALSE; case VT_I2 | VT_BYREF: return *V_I2REF(pVar1) == *V_I2REF(pVar2); case VT_I4 | VT_BYREF: return *V_I4REF(pVar1) == *V_I4REF(pVar2); case VT_R4 | VT_BYREF: return *V_R4REF(pVar1) == *V_R4REF(pVar2); case VT_R8 | VT_BYREF: return *V_R8REF(pVar1) == *V_R8REF(pVar2); case VT_BOOL | VT_BYREF: return *V_BOOLREF(pVar1) == *V_BOOLREF(pVar2); case VT_ERROR | VT_BYREF: return *V_ERRORREF(pVar1) == *V_ERRORREF(pVar2); case VT_CY | VT_BYREF: return memcmp(V_CYREF(pVar1), V_CYREF(pVar2),8)==0; case VT_DATE | VT_BYREF: return *V_DATEREF(pVar1) == *V_DATEREF(pVar2); case VT_BSTR | VT_BYREF: if(fCaseSensitive) return wcscmp(*V_BSTRREF(pVar1), *V_BSTRREF(pVar2)); else return _wcsicmp(*V_BSTRREF(pVar1), *V_BSTRREF(pVar2)); // As we are not testing OLE object, return FALSE for VT_UNKNOWN case VT_UNKNOWN | VT_BYREF: return FALSE; // As we are not testing OLE object, return FALSE for VT_DISPATCH case VT_DISPATCH | VT_BYREF: return FALSE; } return FALSE; }
PHP_COM_DOTNET_API int php_com_copy_variant(VARIANT *dstvar, VARIANT *srcvar) { int ret = SUCCESS; switch (V_VT(dstvar) & ~VT_BYREF) { case VT_EMPTY: case VT_NULL: case VT_VOID: /* should not be possible */ break; case VT_UI1: if (V_VT(dstvar) & VT_BYREF) { *V_UI1REF(dstvar) = V_UI1(srcvar); } else { V_UI1(dstvar) = V_UI1(srcvar); } break; case VT_I1: if (V_VT(dstvar) & VT_BYREF) { *V_I1REF(dstvar) = V_I1(srcvar); } else { V_I1(dstvar) = V_I1(srcvar); } break; case VT_UI2: if (V_VT(dstvar) & VT_BYREF) { *V_UI2REF(dstvar) = V_UI2(srcvar); } else { V_UI2(dstvar) = V_UI2(srcvar); } break; case VT_I2: if (V_VT(dstvar) & VT_BYREF) { *V_I2REF(dstvar) = V_I2(srcvar); } else { V_I2(dstvar) = V_I2(srcvar); } break; case VT_UI4: if (V_VT(dstvar) & VT_BYREF) { *V_UI4REF(dstvar) = V_UI4(srcvar); } else { V_UI4(dstvar) = V_UI4(srcvar); } break; case VT_I4: if (V_VT(dstvar) & VT_BYREF) { *V_I4REF(dstvar) = V_I4(srcvar); } else { V_I4(dstvar) = V_I4(srcvar); } break; #if SIZEOF_ZEND_LONG == 8 case VT_UI8: if (V_VT(dstvar) & VT_BYREF) { *V_UI8REF(dstvar) = V_UI8(srcvar); } else { V_UI8(dstvar) = V_UI8(srcvar); } break; case VT_I8: if (V_VT(dstvar) & VT_BYREF) { *V_I8REF(dstvar) = V_I8(srcvar); } else { V_I8(dstvar) = V_I8(srcvar); } break; #endif case VT_INT: if (V_VT(dstvar) & VT_BYREF) { *V_INTREF(dstvar) = V_INT(srcvar); } else { V_INT(dstvar) = V_INT(srcvar); } break; case VT_UINT: if (V_VT(dstvar) & VT_BYREF) { *V_UINTREF(dstvar) = V_UINT(srcvar); } else { V_UINT(dstvar) = V_UINT(srcvar); } break; case VT_R4: if (V_VT(dstvar) & VT_BYREF) { *V_R4REF(dstvar) = V_R4(srcvar); } else { V_R4(dstvar) = V_R4(srcvar); } break; case VT_R8: if (V_VT(dstvar) & VT_BYREF) { *V_R8REF(dstvar) = V_R8(srcvar); } else { V_R8(dstvar) = V_R8(srcvar); } break; case VT_BOOL: if (V_VT(dstvar) & VT_BYREF) { *V_BOOLREF(dstvar) = V_BOOL(srcvar); } else { V_BOOL(dstvar) = V_BOOL(srcvar); } break; case VT_BSTR: if (V_VT(dstvar) & VT_BYREF) { *V_BSTRREF(dstvar) = V_BSTR(srcvar); } else { V_BSTR(dstvar) = V_BSTR(srcvar); } break; case VT_UNKNOWN: if (V_VT(dstvar) & VT_BYREF) { *V_UNKNOWNREF(dstvar) = V_UNKNOWN(srcvar); } else { V_UNKNOWN(dstvar) = V_UNKNOWN(srcvar); } break; case VT_DISPATCH: if (V_VT(dstvar) & VT_BYREF) { *V_DISPATCHREF(dstvar) = V_DISPATCH(srcvar); } else { V_DISPATCH(dstvar) = V_DISPATCH(srcvar); } break; case VT_VARIANT: return php_com_copy_variant(V_VARIANTREF(dstvar), srcvar); default: php_error_docref(NULL, E_WARNING, "variant->variant: failed to copy from 0x%x to 0x%x", V_VT(dstvar), V_VT(srcvar)); ret = FAILURE; } return ret; }
static void ole_val2ptr_variant(VALUE val, VARIANT *var) { switch (TYPE(val)) { case T_STRING: if (V_VT(var) == (VT_BSTR | VT_BYREF)) { *V_BSTRREF(var) = ole_vstr2wc(val); } break; case T_FIXNUM: switch(V_VT(var)) { case (VT_UI1 | VT_BYREF) : *V_UI1REF(var) = NUM2CHR(val); break; case (VT_I2 | VT_BYREF) : *V_I2REF(var) = (short)NUM2INT(val); break; case (VT_I4 | VT_BYREF) : *V_I4REF(var) = NUM2INT(val); break; case (VT_R4 | VT_BYREF) : *V_R4REF(var) = (float)NUM2INT(val); break; case (VT_R8 | VT_BYREF) : *V_R8REF(var) = NUM2INT(val); break; default: break; } break; case T_FLOAT: switch(V_VT(var)) { case (VT_I2 | VT_BYREF) : *V_I2REF(var) = (short)NUM2INT(val); break; case (VT_I4 | VT_BYREF) : *V_I4REF(var) = NUM2INT(val); break; case (VT_R4 | VT_BYREF) : *V_R4REF(var) = (float)NUM2DBL(val); break; case (VT_R8 | VT_BYREF) : *V_R8REF(var) = NUM2DBL(val); break; default: break; } break; case T_BIGNUM: if (V_VT(var) == (VT_R8 | VT_BYREF)) { *V_R8REF(var) = rb_big2dbl(val); } break; case T_TRUE: if (V_VT(var) == (VT_BOOL | VT_BYREF)) { *V_BOOLREF(var) = VARIANT_TRUE; } break; case T_FALSE: if (V_VT(var) == (VT_BOOL | VT_BYREF)) { *V_BOOLREF(var) = VARIANT_FALSE; } break; default: break; } }
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); }