예제 #1
0
	JNIEXPORT void JNICALL Java_com_tangram_Variant_putVariantLong(JNIEnv *env, jobject _this, jlong longValue)
	{
		VARIANT *v = extractVariant(env, _this);
		if (v) {
			VariantClear(v); // whatever was there before
			V_VT(v) = VT_I8;
			V_I8(v) = (LONGLONG)longValue;
		}
		else ThrowComFail(env, "putVariantLong failed", -1);
	}
예제 #2
0
	JNIEXPORT jlong JNICALL Java_com_tangram_Variant_getVariantLong
		(JNIEnv *env, jobject _this)
	{
		VARIANT *v = extractVariant(env, _this);
		if (v) {
			if (V_VT(v) != VT_I8) {
				return NULL;
			}
			return (jlong)V_I8(v);
		}
		return NULL;
	}
예제 #3
0
파일: TclObject.cpp 프로젝트: jbroll/tcom
void
TclObject::toNativeValue (NativeValue *pDest,
                          const Type &type,
                          Tcl_Interp *interp,
                          bool addRef)
{
#ifdef V_I8
    VARTYPE vt = type.vartype();
    if (vt == VT_I8 || vt == VT_UI8) {
        pDest->fixInvalidVariantType();
        VariantClear(pDest);
        V_VT(pDest) = vt;
        Tcl_GetWideIntFromObj(interp, m_pObj, &V_I8(pDest));
        return;
    }
#endif

    pDest->fixInvalidVariantType();
    toVariant(pDest, type, interp, addRef);
}
/////////////////////////////////////////////////////////////////
// myAddProperty
//
//	This function initializes the property structure pProp
//
/////////////////////////////////////////////////////////////////
void myAddProperty
	(
	DBPROP *				pProp, 
	DBPROPID				dwPropertyID, 
	VARTYPE					vtType, 
	LONG_PTR				lValue, 
	DBPROPOPTIONS			dwOptions
	)
{
	// Set up the property structure
	pProp->dwPropertyID		= dwPropertyID;
	pProp->dwOptions		= dwOptions;
	pProp->dwStatus			= DBPROPSTATUS_OK;
	pProp->colid			= DB_NULLID;
	V_VT(&pProp->vValue)	= vtType;

	// Since VARIANT data is a union, we can place the value in any
	// member (except for VT_DECIMAL, which is a union with the whole
	// VARIANT structure -- but we know we're not passing VT_DECIMAL)
	if (vtType != VT_I8)
		V_I4(&pProp->vValue)	= (LONG)lValue;
	else 
		V_I8(&pProp->vValue)	= lValue;
}
예제 #5
0
static void
ole_set_byref(VARIANT *realvar, VARIANT *var,  VARTYPE vt)
{
    V_VT(var) = vt;
    if (vt == (VT_VARIANT|VT_BYREF)) {
        V_VARIANTREF(var) = realvar;
    } else {
        if (V_VT(realvar) != (vt & ~VT_BYREF)) {
            rb_raise(eWIN32OLERuntimeError, "variant type mismatch");
        }
        switch(vt & ~VT_BYREF) {
        case VT_I1:
            V_I1REF(var) = &V_I1(realvar);
            break;
        case VT_UI1:
            V_UI1REF(var) = &V_UI1(realvar);
            break;
        case VT_I2:
            V_I2REF(var) = &V_I2(realvar);
            break;
        case VT_UI2:
            V_UI2REF(var) = &V_UI2(realvar);
            break;
        case VT_I4:
            V_I4REF(var) = &V_I4(realvar);
            break;
        case VT_UI4:
            V_UI4REF(var) = &V_UI4(realvar);
            break;
        case VT_R4:
            V_R4REF(var) = &V_R4(realvar);
            break;
        case VT_R8:
            V_R8REF(var) = &V_R8(realvar);
            break;

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

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

        case VT_CY:
            V_CYREF(var) = &V_CY(realvar);
            break;
        case VT_DATE:
            V_DATEREF(var) = &V_DATE(realvar);
            break;
        case VT_BSTR:
            V_BSTRREF(var) = &V_BSTR(realvar);
            break;
        case VT_DISPATCH:
            V_DISPATCHREF(var) = &V_DISPATCH(realvar);
            break;
        case VT_ERROR:
            V_ERRORREF(var) = &V_ERROR(realvar);
            break;
        case VT_BOOL:
            V_BOOLREF(var) = &V_BOOL(realvar);
            break;
        case VT_UNKNOWN:
            V_UNKNOWNREF(var) = &V_UNKNOWN(realvar);
            break;
        case VT_ARRAY:
            V_ARRAYREF(var) = &V_ARRAY(realvar);
            break;
        default:
            rb_raise(eWIN32OLERuntimeError, "unknown type specified(setting BYREF):%d", vt);
            break;
        }
    }
}
예제 #6
0
static HRESULT ExtractArgument(VARIANT * pvArg, WCHAR chIdentifier, BOOL * pbFreeArg, va_list * marker)
{
	HRESULT hr = NOERROR;

	*pbFreeArg = FALSE;

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

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

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

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

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

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

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

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

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

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

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

			*pbFreeArg = TRUE;
			break;
		}

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

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

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

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

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

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

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

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

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

	return hr;
}
예제 #7
0
HRESULT dhGetValueV(LPCWSTR szIdentifier, void * pResult, IDispatch * pDisp, LPCOLESTR szMember, va_list * marker)
{
	VARIANT vtResult;
	VARTYPE returnType;
	HRESULT hr;

	DH_ENTER(L"GetValueV");

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

	return DH_EXIT(hr, szMember);
}
예제 #8
0
파일: variant.cpp 프로젝트: ArildF/masters
STDAPI
VariantChangeType(
    VARIANTARG FAR* pvargDest,
    VARIANTARG FAR* pvargSrc,
    unsigned short wFlags,
    VARTYPE vt)
{
    VARIANT varTmp;
    HRESULT hresult;
    VARTYPE vtSrc;

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

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

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

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

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

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

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

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

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


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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    return NOERROR;

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

LError0:;
    return hresult;
}
예제 #9
0
LPCTSTR COcsWmi::strVariant( VARIANT pVal)

{

	static CString strRet;



	strRet = _T( "N/A");

	switch(pVal.vt){

		case VT_EMPTY:

		case VT_NULL:

			strRet = _T( "");

			break;

		case VT_I1:

			strRet.Format(_T( "%hd"),V_I2(&pVal));

			break;

		case VT_I2:

			strRet.Format(_T( "%d"),V_I2(&pVal));

			break;

		case VT_I4:

			strRet.Format(_T( "%ld"),V_I4(&pVal));

			break;

		case VT_I8:

			strRet.Format(_T( "%I64d"), V_I8(&pVal));

			break; 

		case VT_UI1:

			strRet.Format(_T( "%hu"),V_UI1(&pVal));

			break;

		case VT_UI2:

			strRet.Format(_T( "%u"),V_UI2(&pVal));

			break;

		case VT_UI4:

			strRet.Format(_T( "%lu"),V_UI4(&pVal));

			break;

		case VT_UI8:

			strRet.Format(_T( "%I64u"),V_UI8(&pVal));

			break;

		case VT_INT:

			strRet.Format(_T( "%d"),V_INT(&pVal));

			break;

		case VT_UINT:

			strRet.Format(_T( "%u"),V_UINT(&pVal));

			break;

		case VT_R4:

			strRet.Format(_T( "%e"),V_R4(&pVal));

			break;

		case VT_R8:

			strRet.Format(_T( "%le"),V_R8(&pVal));

			break;

		case VT_CY:

			strRet = COleCurrency(pVal).Format();

			break;

		case VT_DATE:

			strRet = COleDateTime(pVal).Format( VAR_DATEVALUEONLY);

			break;

		case VT_BSTR:

			strRet = V_BSTRT(&pVal);

			break;

		case VT_DISPATCH:

			strRet = _T( "VT_DISPATCH");

			break;

		case VT_ERROR:

			strRet = _T( "VT_ERROR");

			break;

		case VT_BOOL:

			return (V_BOOL(&pVal) ? _T("TRUE") : _T("FALSE"));

		case VT_VARIANT:

			strRet = _T( "VT_VARIANT");

			break;

		case VT_UNKNOWN:

			strRet = _T( "VT_UNKNOWN");

			break;

		case VT_VOID:

			strRet = _T( "VT_VOID");

			break;

		case VT_HRESULT:

			strRet = _T( "VT_HRESULT");

			break;

		case VT_PTR:

			strRet = _T( "VT_PTR");

			break;

		case VT_SAFEARRAY:

			strRet = _T( "VT_SAFEARRAY");

			break;

		case VT_CARRAY:

			strRet = _T( "VT_CARRAY");

			break;

		case VT_USERDEFINED:

			strRet = _T( "VT_USERDEFINED");

			break;

		case VT_LPSTR:

			strRet = _T( "VT_LPSTR");

			break;

		case VT_LPWSTR:

			strRet = _T( "VT_LPWSTR");

			break;

		case VT_FILETIME:

			strRet = _T( "VT_FILETIME");

			break;

		case VT_BLOB:

			strRet = _T( "VT_BLOB");

			break;

		case VT_STREAM:

			strRet = _T( "VT_STREAM");

			break;

		case VT_STORAGE:

			strRet = _T( "VT_STORAGE");

			break;

		case VT_STREAMED_OBJECT:

			strRet = _T( "VT_STREAMED_OBJECT");

			break;

		case VT_STORED_OBJECT:

			strRet = _T( "VT_STORED_OBJECT");

			break;

		case VT_BLOB_OBJECT:

			strRet = _T( "VT_BLOB_OBJECT");

			break;

		case VT_CF:

			strRet = _T( "VT_CF");

			break;

		case VT_CLSID:

			strRet = _T( "VT_CLSID");

			break;

	}

	return strRet;

}
예제 #10
0
파일: TclObject.cpp 프로젝트: jbroll/tcom
TclObject::TclObject (VARIANT *pSrc, const Type &type, Tcl_Interp *interp, int bytes)
{
    if (V_ISARRAY(pSrc)) {
        SAFEARRAY *psa = V_ISBYREF(pSrc) ? *V_ARRAYREF(pSrc) : V_ARRAY(pSrc);
        VARTYPE elementType = V_VT(pSrc) & VT_TYPEMASK;
        unsigned numDimensions = SafeArrayGetDim(psa);
        std::vector<long> indices(numDimensions);

        m_pObj = convertFromSafeArray( psa, elementType, 1, &indices[0], type, interp, bytes);

    } else if (vtMissing == pSrc) {
        m_pObj = Extension::newNaObj();

    } else {
        switch (V_VT(pSrc)) {
        case VT_BOOL:
            m_pObj = Tcl_NewBooleanObj(V_BOOL(pSrc));
            break;

        case VT_ERROR:
            m_pObj = Tcl_NewLongObj(V_ERROR(pSrc));
            break;

        case VT_I1:
        case VT_UI1:
            m_pObj = Tcl_NewLongObj(V_I1(pSrc));
            break;

        case VT_I2:
        case VT_UI2:
            m_pObj = Tcl_NewLongObj(V_I2(pSrc));
            break;

        case VT_I4:
        case VT_UI4:
        case VT_INT:
        case VT_UINT:
            m_pObj = Tcl_NewLongObj(V_I4(pSrc));
            break;

#ifdef V_I8
        case VT_I8:
        case VT_UI8:
            m_pObj = Tcl_NewWideIntObj(V_I8(pSrc));
            break;
#endif

        case VT_R4:
            m_pObj = Tcl_NewDoubleObj(V_R4(pSrc));
            break;

        case VT_DATE:
        case VT_R8:
            m_pObj = Tcl_NewDoubleObj(V_R8(pSrc));
            break;

        case VT_DISPATCH:
            m_pObj = convertFromUnknown(V_DISPATCH(pSrc), type.iid(), interp);
            break;

        case VT_DISPATCH | VT_BYREF:
            m_pObj = convertFromUnknown(
                (V_DISPATCHREF(pSrc) != 0) ? *V_DISPATCHREF(pSrc) : 0,
                type.iid(),
                interp);
            break;

        case VT_UNKNOWN:
            m_pObj = convertFromUnknown(V_UNKNOWN(pSrc), type.iid(), interp);
            break;

        case VT_UNKNOWN | VT_BYREF:
            m_pObj = convertFromUnknown(
                (V_UNKNOWNREF(pSrc) != 0) ? *V_UNKNOWNREF(pSrc) : 0,
                type.iid(),
                interp);
            break;

        case VT_NULL:
            m_pObj = Extension::newNullObj();
            break;

        case VT_LPSTR:
            m_pObj = Tcl_NewStringObj(V_I1REF(pSrc), -1);
            break;

        case VT_LPWSTR:
            {
#if TCL_MINOR_VERSION >= 2
                // Uses Unicode function introduced in Tcl 8.2.
                m_pObj = newUnicodeObj(V_UI2REF(pSrc), -1);
#else
		const wchar_t *pWide = V_UI2REF(pSrc);
                _bstr_t str(pWide);
                m_pObj = Tcl_NewStringObj(str, -1);
#endif
            }
            break;

        default:
            if (V_VT(pSrc) == VT_USERDEFINED && type.name() == "GUID") {
                Uuid uuid(*static_cast<UUID *>(V_BYREF(pSrc)));
                m_pObj = Tcl_NewStringObj(
                    const_cast<char *>(uuid.toString().c_str()), -1);
            } else {
                if (V_VT(pSrc) == (VT_VARIANT | VT_BYREF)) {
                    pSrc = V_VARIANTREF(pSrc);
                }

                _bstr_t str(pSrc);
#if TCL_MINOR_VERSION >= 2
                // Uses Unicode function introduced in Tcl 8.2.
		wchar_t *pWide = str;
                m_pObj = newUnicodeObj(
                    reinterpret_cast<Tcl_UniChar *>(pWide), str.length());
#else
                m_pObj = Tcl_NewStringObj(str, -1);
#endif
            }
        }
    }

    Tcl_IncrRefCount(m_pObj);
}
예제 #11
0
PHP_COM_DOTNET_API void php_com_variant_from_zval(VARIANT *v, zval *z, int codepage)
{
	OLECHAR *olestring;
	php_com_dotnet_object *obj;
	zend_uchar ztype = IS_NULL;

	if (z) {
		ZVAL_DEREF(z);
		ztype = Z_TYPE_P(z);
	}

	switch (ztype) {
		case IS_NULL:
			V_VT(v) = VT_NULL;
			break;

		case IS_FALSE:
			V_VT(v) = VT_BOOL;
			V_BOOL(v) = VARIANT_FALSE;
			break;

		case IS_TRUE:
			V_VT(v) = VT_BOOL;
			V_BOOL(v) = VARIANT_TRUE;
			break;

		case IS_OBJECT:
			if (php_com_is_valid_object(z)) {
				obj = CDNO_FETCH(z);
				if (V_VT(&obj->v) == VT_DISPATCH) {
					/* pass the underlying object */
					V_VT(v) = VT_DISPATCH;
					if (V_DISPATCH(&obj->v)) {
						IDispatch_AddRef(V_DISPATCH(&obj->v));
					}
					V_DISPATCH(v) = V_DISPATCH(&obj->v);
				} else {
					/* pass the variant by reference */
					V_VT(v) = VT_VARIANT | VT_BYREF;
					V_VARIANTREF(v) = &obj->v;
				}
			} else {
				/* export the PHP object using our COM wrapper */
				V_VT(v) = VT_DISPATCH;
				V_DISPATCH(v) = php_com_wrapper_export(z);
			}
			break;

		case IS_ARRAY:
			/* map as safe array */
			safe_array_from_zval(v, z, codepage);
			break;

		case IS_LONG:
#if SIZEOF_ZEND_LONG == 4
			V_VT(v) = VT_I4;
			V_I4(v) = Z_LVAL_P(z);
#else
			V_VT(v) = VT_I8;
			V_I8(v) = Z_LVAL_P(z);
#endif
			break;

		case IS_DOUBLE:
			V_VT(v) = VT_R8;
			V_R8(v) = Z_DVAL_P(z);
			break;

		case IS_STRING:
			V_VT(v) = VT_BSTR;
			olestring = php_com_string_to_olestring(Z_STRVAL_P(z), Z_STRLEN_P(z), codepage);
			if (CP_UTF8 == codepage) {
				V_BSTR(v) = SysAllocStringByteLen((char*)olestring, (UINT)(wcslen(olestring) * sizeof(OLECHAR)));
			} else {
				V_BSTR(v) = SysAllocStringByteLen((char*)olestring, (UINT)(Z_STRLEN_P(z) * sizeof(OLECHAR)));
			}
			efree(olestring);
			break;

		case IS_RESOURCE:
		case IS_CONSTANT_AST:
		default:
			V_VT(v) = VT_NULL;
			break;
	}
}
예제 #12
0
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;
}
예제 #13
0
PHP_COM_DOTNET_API int php_com_zval_from_variant(zval *z, VARIANT *v, int codepage)
{
	OLECHAR *olestring = NULL;
	int ret = SUCCESS;

	switch (V_VT(v)) {
		case VT_EMPTY:
		case VT_NULL:
		case VT_VOID:
			ZVAL_NULL(z);
			break;
		case VT_UI1:
			ZVAL_LONG(z, (zend_long)V_UI1(v));
			break;
		case VT_I1:
			ZVAL_LONG(z, (zend_long)V_I1(v));
			break;
		case VT_UI2:
			ZVAL_LONG(z, (zend_long)V_UI2(v));
			break;
		case VT_I2:
			ZVAL_LONG(z, (zend_long)V_I2(v));
			break;
		case VT_UI4:  /* TODO: promote to double if large? */
			ZVAL_LONG(z, (long)V_UI4(v));
			break;
		case VT_I4:
			ZVAL_LONG(z, (long)V_I4(v));
			break;
#if SIZEOF_ZEND_LONG == 8
		case VT_UI8:
			ZVAL_LONG(z, (zend_long)V_UI8(v));
			break;
		case VT_I8:
			ZVAL_LONG(z, (zend_long)V_I8(v));
			break;
#endif
		case VT_INT:
			ZVAL_LONG(z, V_INT(v));
			break;
		case VT_UINT: /* TODO: promote to double if large? */
			ZVAL_LONG(z, (zend_long)V_UINT(v));
			break;
		case VT_R4:
			ZVAL_DOUBLE(z, (double)V_R4(v));
			break;
		case VT_R8:
			ZVAL_DOUBLE(z, V_R8(v));
			break;
		case VT_BOOL:
			ZVAL_BOOL(z, V_BOOL(v) ? 1 : 0);
			break;
		case VT_BSTR:
			olestring = V_BSTR(v);
			if (olestring) {
				size_t len;
				char *str = php_com_olestring_to_string(olestring,
					&len, codepage);
				ZVAL_STRINGL(z, str, len);
				// TODO: avoid reallocation???
				efree(str);
				olestring = NULL;
			}
			break;
		case VT_UNKNOWN:
			if (V_UNKNOWN(v) != NULL) {
				IDispatch *disp;

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

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

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

		default:
			php_com_wrap_variant(z, v, codepage);
	}

	if (olestring) {
		efree(olestring);
	}

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

	return ret;
}