VARIANT CBoxEncoding::StrToBin(VARIANT& var, VARIANT &varCP) { CBoxBinPtr varString(var, VT_BSTR); UINT nCodePage; if(varCP.vt == VT_ERROR) nCodePage = _AtlGetConversionACP(); else { CComVariant varTemp; varTemp.ChangeType(VT_I4, &varCP); if(varTemp.vt == VT_I4) nCodePage = varTemp.lVal; else AfxThrowOleException(TYPE_E_TYPEMISMATCH); } int _nTempCount = ::WideCharToMultiByte(nCodePage, 0, LPWSTR(varString.m_pData), varString.m_nSize, NULL, 0, NULL, NULL); CBoxBinPtr varPtr(_nTempCount); ::WideCharToMultiByte(nCodePage, 0, LPWSTR(varString.m_pData), varString.m_nSize, varPtr, _nTempCount, NULL, NULL); return varPtr; }
/*************************************************************************** * call method ***************************************************************************/ void CErrorObject::call( CCilVm* const pVm, const int32_t iNumArguments, CVariable* pArguments ) { CVariable obj; CVmObject* pObj = pVm->createObject( pVm->getErrorObjectRID() ); obj.setObjectRef( pObj ); //Set prototype: String prototype object obj.refObject->setPrototypeObject( &pVm->getPrototypeObject( pVm->getErrorObjectRID() ) ); if( iNumArguments > 2 ) { pArguments ++; CVariable& var = *pArguments; var.setFlag( OPERAND_FLAG( OPERAND_FLAG_DONTENUM | OPERAND_FLAG_DONTDELETE ) ); obj.refObject->setProperty( NAME_BUILTIN_ERROR_PROPERTY_NUMBER, var ) ; pArguments ++; var = *pArguments; var.convertToString( pVm ); var.setFlag( OPERAND_FLAG( OPERAND_FLAG_DONTENUM | OPERAND_FLAG_DONTDELETE ) ); obj.refObject->setProperty( NAME_BUILTIN_ERROR_PROPERTY_MESSAGE, var ); } else if( iNumArguments > 1 ) { pArguments ++; CVariable& var = *pArguments; var.convertToString( pVm ); var.setFlag( OPERAND_FLAG( OPERAND_FLAG_DONTENUM | OPERAND_FLAG_DONTDELETE ) ); obj.refObject->setProperty( NAME_BUILTIN_ERROR_PROPERTY_MESSAGE, var ); CVariable varError( ERROR_PROPERTY_NUMBER_DEFAULT, OPERAND_FLAG( OPERAND_FLAG_DONTENUM | OPERAND_FLAG_DONTDELETE ) ); obj.refObject->setProperty( NAME_BUILTIN_ERROR_PROPERTY_NUMBER, varError ); } else { CVariable varString( L"", OPERAND_FLAG( OPERAND_FLAG_DONTENUM | OPERAND_FLAG_DONTDELETE ) ); CVariable varError( ERROR_PROPERTY_NUMBER_DEFAULT, OPERAND_FLAG( OPERAND_FLAG_DONTENUM | OPERAND_FLAG_DONTDELETE ) ); obj.refObject->setProperty( NAME_BUILTIN_ERROR_PROPERTY_MESSAGE, varString ); obj.refObject->setProperty( NAME_BUILTIN_ERROR_PROPERTY_NUMBER, varError ); } CVariable var( L"", OPERAND_FLAG( OPERAND_FLAG_DONTENUM | OPERAND_FLAG_DONTDELETE ) ); obj.refObject->setProperty( NAME_BUILTIN_ERROR_PROPERTY_NAME, var ); //Push the ObjectRef to a eval stack pVm->pushEvalStackVariable( obj ); return; }
/*************************************************************************** * ctor ***************************************************************************/ void CErrorObject::ctor( CCilVm* const pVm, const int32_t iNumArguments, CVariable* pArguments ) { CVariable obj = *pArguments; assert( obj.iOperandType == OPERAND_OBJECTREF ); obj.refObject->setRID( pVm->getErrorObjectRID() ); //Set prototype: String prototype object obj.refObject->setPrototypeObject( &pVm->getPrototypeObject( pVm->getErrorObjectRID() ) ); if( iNumArguments > 2 ) { pArguments ++; CVariable& var = *pArguments; var.setFlag( OPERAND_FLAG( OPERAND_FLAG_DONTENUM | OPERAND_FLAG_DONTDELETE ) ); obj.refObject->setProperty( NAME_BUILTIN_ERROR_PROPERTY_NUMBER, var ) ; pArguments ++; CVariable& varMessage = *pArguments; varMessage.convertToString( pVm ); varMessage.setFlag( OPERAND_FLAG( OPERAND_FLAG_DONTENUM | OPERAND_FLAG_DONTDELETE ) ); obj.refObject->setProperty( NAME_BUILTIN_ERROR_PROPERTY_MESSAGE, varMessage ); } else if( iNumArguments > 1 ) { pArguments ++; CVariable& var = *pArguments; var.convertToString( pVm ); var.setFlag( OPERAND_FLAG( OPERAND_FLAG_DONTENUM | OPERAND_FLAG_DONTDELETE ) ); obj.refObject->setProperty( NAME_BUILTIN_ERROR_PROPERTY_MESSAGE, var ); CVariable varError( ERROR_PROPERTY_NUMBER_DEFAULT, OPERAND_FLAG( OPERAND_FLAG_DONTENUM | OPERAND_FLAG_DONTDELETE ) ); obj.refObject->setProperty( NAME_BUILTIN_ERROR_PROPERTY_NUMBER, varError ); } else { CVariable varString( L"", OPERAND_FLAG( OPERAND_FLAG_DONTENUM | OPERAND_FLAG_DONTDELETE ) ); CVariable varError( ERROR_PROPERTY_NUMBER_DEFAULT, OPERAND_FLAG( OPERAND_FLAG_DONTENUM | OPERAND_FLAG_DONTDELETE ) ); obj.refObject->setProperty( NAME_BUILTIN_ERROR_PROPERTY_MESSAGE, varString ); obj.refObject->setProperty( NAME_BUILTIN_ERROR_PROPERTY_NUMBER, varError ); } CVariable var( L"", OPERAND_FLAG( OPERAND_FLAG_DONTENUM | OPERAND_FLAG_DONTDELETE ) ); obj.refObject->setProperty( NAME_BUILTIN_ERROR_PROPERTY_NAME, var ); }