HRESULT CPigEngine::put_ScriptDir(BSTR bstrScriptDir) { // Get the number of pigs that exist XLock lock(this); long cPigs = 0; if (m_pPigs) RETURN_FAILED(m_pPigs->get_Count(&cPigs)); // Fail if there are any pigs in existance if (cPigs) return AtlReportError(CLSID_PigSession, IDS_E_PROPUT_PIGSEXIST, IID_IPigSession, 0, _Module.GetResourceInstance()); // Open the registry key of the AppID CRegKey key; RETURN_FAILED(_Module.OpenAppIDRegKey(key)); // Save the specified value USES_CONVERSION; _bstr_t bstrValue(bstrScriptDir); long lr = key.SetValue(OLE2CT(bstrValue), TEXT("ScriptDir")); if (ERROR_SUCCESS != lr) return HRESULT_FROM_WIN32(lr); // Indicate success return S_OK; }
STDMETHODIMP CCoAutoRun::ReadINF(BSTR section, BSTR key, VARIANT defaultValue, BSTR* retValue) { TCHAR moduleDir[MAX_PATH] = {0}; // Get the autorun.exe's path ATLENSURE( ::GetModuleFileName(NULL, moduleDir, MAX_PATH) ); ::PathRemoveFileSpec(moduleDir); TCHAR autoRunInfPath[MAX_PATH] = {0}; ATLENSURE_SUCCEEDED( ::StringCchCopy(autoRunInfPath, MAX_PATH, moduleDir) ); ::PathAppend(autoRunInfPath, _T("AUTORUN.INF")); CComVariant vDefaultValue(defaultValue); ATLENSURE_SUCCEEDED(vDefaultValue.ChangeType(VT_BSTR)); // Read [HTML] HTML=... TCHAR value[255] = {0}; GetPrivateProfileString( COLE2CT(section), COLE2CT(key), COLE2CT(vDefaultValue.bstrVal), value, 255, autoRunInfPath); CComBSTR bstrValue(value); *retValue = bstrValue.Detach(); return S_OK; }
/*--------------------------------------------------------------------------- * AddElement * Add XML Element * */ void DOMXMLBuilder::AddElement(const string &inTag, const string &value) { HRESULT hr; MSXML2::IXMLDOMElement *newElement = NULL; if (m_CurrentNode == NULL) { m_HasError = true; m_ErrorMsg = "Cannot add element. Current node is NULL!"; return; } // Create new element CComBSTR tag(inTag.c_str()); hr = m_XMLDoc ->createElement(tag.m_str, &newElement); if (FAILED(hr)){ // create element failed m_HasError = true; m_ErrorMsg = "createElement for new element failed"; return; } CComBSTR bstrValue(value.c_str()); // Set the value newElement ->put_text(bstrValue); // Append it to the current node MSXML2::IXMLDOMNode *tmpNode; hr = m_CurrentNode ->appendChild(newElement, &tmpNode); if (FAILED(hr)) { // failed m_HasError = true; m_ErrorMsg = "appendChild on new element failed"; newElement ->Release(); return; } tmpNode ->Release(); newElement ->Release(); }
HRESULT CPigEngine::put_ArtPath(BSTR bstrArtPath) { // Open the registry key of the AppID CRegKey key; RETURN_FAILED(_Module.OpenAppIDRegKey(key)); // Save the specified value USES_CONVERSION; _bstr_t bstrValue(bstrArtPath); long lr = key.SetValue(OLE2CT(bstrValue), TEXT("ArtPath")); if (ERROR_SUCCESS != lr) return HRESULT_FROM_WIN32(lr); // Set the art path in the Allegiance stuff //USES_CONVERSION; UTL::SetArtPath(OLE2CA(bstrValue)); // Indicate success return S_OK; }
/** * Handles the setregisters sub-command. * * @returns Suitable exit code. * @param pArgs The handler arguments. * @param pDebugger Pointer to the debugger interface. */ static RTEXITCODE handleDebugVM_SetRegisters(HandlerArg *pArgs, IMachineDebugger *pDebugger) { /* * We take a list of register assignments, that is register=value. */ ULONG idCpu = 0; com::SafeArray<IN_BSTR> aBstrNames; com::SafeArray<IN_BSTR> aBstrValues; RTGETOPTSTATE GetState; RTGETOPTUNION ValueUnion; static const RTGETOPTDEF s_aOptions[] = { { "--cpu", 'c', RTGETOPT_REQ_UINT32 }, }; int rc = RTGetOptInit(&GetState, pArgs->argc, pArgs->argv, s_aOptions, RT_ELEMENTS(s_aOptions), 2, RTGETOPTINIT_FLAGS_OPTS_FIRST); AssertRCReturn(rc, RTEXITCODE_FAILURE); while ((rc = RTGetOpt(&GetState, &ValueUnion)) != 0) { switch (rc) { case 'c': idCpu = ValueUnion.u32; break; case VINF_GETOPT_NOT_OPTION: { const char *pszEqual = strchr(ValueUnion.psz, '='); if (!pszEqual) return errorSyntax("setregisters expects input on the form 'register=value' got '%s'", ValueUnion.psz); try { com::Bstr bstrName(ValueUnion.psz, pszEqual - ValueUnion.psz); com::Bstr bstrValue(pszEqual + 1); if ( !aBstrNames.push_back(bstrName.raw()) || !aBstrValues.push_back(bstrValue.raw())) throw std::bad_alloc(); } catch (std::bad_alloc) { RTMsgError("Out of memory\n"); return RTEXITCODE_FAILURE; } break; } default: return errorGetOpt(rc, &ValueUnion); } } if (!aBstrNames.size()) return errorSyntax("The setregisters sub-command takes at least one register name"); /* * If it is only one register, use the single register method just so * we expose it and can test it from the command line. */ if (aBstrNames.size() == 1) { CHECK_ERROR2I_RET(pDebugger, SetRegister(idCpu, aBstrNames[0], aBstrValues[0]), RTEXITCODE_FAILURE); RTPrintf("Successfully set %ls\n", aBstrNames[0]); } else { CHECK_ERROR2I_RET(pDebugger, SetRegisters(idCpu, ComSafeArrayAsInParam(aBstrNames), ComSafeArrayAsInParam(aBstrValues)), RTEXITCODE_FAILURE); RTPrintf("Successfully set %u registers\n", aBstrNames.size()); } return RTEXITCODE_SUCCESS; }