STDMETHODIMP MailPropertyMap::get_Item(BSTR index, BSTR* pVal) { try { if(0 == index) throw Workshare::ArgumentNullException(_T("index"), _T("The property index may not be null.")); if(0 == pVal) throw Workshare::ArgumentNullException(_T("pVal"), _T("The return buffer for the property value must be valid.")); _bstr_t indexName(index); _wcslwr(indexName); *pVal = SysAllocString(m_map[indexName.GetBSTR()].c_str()); return S_OK; } catch(Workshare::Exception const& e) { return AtlReportError(__uuidof(this), e.Message, __uuidof(IMailPropertyMap), e.ErrorCode); } catch(...) { return AtlReportError(__uuidof(this), L"Unexpected Error", __uuidof(IMailPropertyMap), ProcessUnhandledException()); } }
static HRESULT WINAPI GetArrayFromVariant(VARIANT* pVar, SAFEARRAY** pparray) { ATLASSERT(pVar); ATLASSERT(pparray); *pparray = nullptr; VARIANT* pVarTmp; pVarTmp = pVar->vt == (VT_VARIANT|VT_BYREF) ? pVar->pvarVal : pVar; //typical for script clients if(pVarTmp == nullptr) { return E_INVALIDARG; } if( (pVarTmp->vt & VT_ARRAY) == 0 ) { return AtlReportError(GUID_NULL, L"Array expected", IID_NULL, E_INVALIDARG); } *pparray = (pVarTmp->vt & VT_BYREF) ? *(pVarTmp->pparray) : pVarTmp->parray; if(*pparray == nullptr) { return E_POINTER; } if(SafeArrayGetDim(*pparray) != 1) { return AtlReportError(GUID_NULL, L"Unidimensional array expected", IID_NULL, E_INVALIDARG); } return S_OK; }
STDMETHODIMP MailPropertyMap::put_Item(BSTR index, BSTR newVal) { try { if(0 == index) throw Workshare::ArgumentNullException(_T("index"), _T("The property index may not be null.")); _bstr_t indexName(index); _wcslwr(indexName); if(0 != newVal) m_map[indexName.GetBSTR()] = newVal; else m_map[indexName.GetBSTR()] = L""; return S_OK; } catch(Workshare::Exception const& e) { return AtlReportError(__uuidof(this),e.Message, __uuidof(IMailPropertyMap), e.ErrorCode); } catch(...) { return AtlReportError(__uuidof(this),L"Unexpected Error", __uuidof(IMailPropertyMap), ProcessUnhandledException()); } }
STDMETHODIMP Profile::put_Languages(SAFEARRAY * newVal) { try { VARTYPE vt = VT_UNKNOWN; SafeArrayGetVartype(newVal, & vt); UINT uiDim = SafeArrayGetDim(newVal); if((uiDim != 1) || (vt != VT_BSTR)) { return AtlReportError(GetObjectCLSID(), L"Array of languages must be single dimension array of strings", GUID_NULL, E_INVALIDARG); } HRESULT hr = SafeArrayLock(newVal); if(FAILED(hr)) { return AtlReportError(GetObjectCLSID(), L"Unable to lock array", GUID_NULL, E_FAIL); } BSTR * pItems = (BSTR *) newVal->pvData; wstring wstrItems; for(ULONG l = 0; l < newVal->rgsabound[0].cElements; l++) { if(l > 0) wstrItems += L" "; wstrItems += pItems[l]; } SafeArrayUnlock(newVal); gSkypeQueue.SetProperty(L"PROFILE", L"", L"LANGUAGES", wstrItems.c_str()); return S_OK; } catch (const WCHAR * err) { return AtlReportError(GetObjectCLSID(), err, GUID_NULL, E_FAIL); } }
HRESULT CPigEngine::CreatePig(BSTR bstrType, BSTR bstrCommandLine, IPig** ppPig) { // Initialize the [out] parameter CLEAROUT(ppPig, (IPig*)NULL); // Lock the object for the following validation checks { XLock lock(this); // Ensure that the scripts have been loaded RETURN_FAILED(EnsureScriptsAreLoaded()); // Ensure that the MissionServer property is not empty if (!m_bstrMissionServer.Length()) return AtlReportError(CLSID_PigSession, IDS_E_NO_MISSIONSRV, IID_IPigSession, 0, _Module.GetResourceInstance()); // Get the number of pigs that exist long cPigs = 0; if (m_pPigs) _SVERIFYE(m_pPigs->get_Count(&cPigs)); // Get the maximum number of pigs allowed long nMaxPigs = 0; _SVERIFYE(get_MaxPigs(&nMaxPigs)); // Check for maximum pigs if (nMaxPigs >= 0 && cPigs >= nMaxPigs) return AtlReportError(CLSID_PigSession, IDS_E_TOOMANYPIGS, IID_IPigSession, 0, _Module.GetResourceInstance()); } // bstrType is optional, so assign a default value if not specified CComBSTR bstrTheType(bstrType); if (!bstrTheType.Length()) bstrTheType = L"Default"; // Find the specified behavior type CPigBehaviorScriptType* pBehaviorType = GetBehaviorType(bstrTheType); if (!pBehaviorType) return AtlReportError(CLSID_PigSession, IDS_E_CREATE_BEHAVIOR_TYPE, IID_IPigSession, 0, _Module.GetResourceInstance()); // Create a new pig thread object and it's associated pig player object DWORD dwGITCookie; RETURN_FAILED(CPig::Create(pBehaviorType, bstrCommandLine, &dwGITCookie)); // Get an apartment-safe pointer to the pig object RETURN_FAILED(GetInterfaceFromGlobal(dwGITCookie, IID_IPig, (void**)ppPig)); assert(*ppPig); // Indicate success return S_OK; }
STDMETHODIMP Profile::get_Languages(SAFEARRAY ** pVal) { try { WCHAR * pResult = gSkypeQueue.RetrieveProperty(L"PROFILE", L"", L"LANGUAGES"); long lTotal=0, lCtr=0; HRESULT hr; BSTR * pItems; for(int i = 0; i < 2; i++) { WCHAR *next_token = NULL; WCHAR * pItem = wcstok_s(pResult, L" ", &next_token); while(pItem != NULL) { if(wcslen(pItem) > 0) { if(i == 0) { lTotal++; } else { pItems[lCtr++] = SysAllocString(pItem); } } pItem = wcstok_s(NULL, L" ", &next_token); } if(i == 0) { SAFEARRAYBOUND sba; sba.cElements = lTotal; sba.lLbound = 0; *pVal = SafeArrayCreateEx(VT_BSTR, 1, & sba, NULL); if((*pVal) == NULL) { return AtlReportError(GetObjectCLSID(), L"Unable to create array", GUID_NULL, E_FAIL); } hr = SafeArrayLock(*pVal); if(FAILED(hr)) { return AtlReportError(GetObjectCLSID(), L"Unable to lock array", GUID_NULL, E_FAIL); } pItems = (BSTR *) (*pVal)->pvData; } else { hr = SafeArrayUnlock(*pVal); if(FAILED(hr)) { return AtlReportError(GetObjectCLSID(), L"Unable to unlock array", GUID_NULL, E_FAIL); } } } free(pResult); return S_OK; } catch (const WCHAR * err) { return AtlReportError(GetObjectCLSID(), err, GUID_NULL, E_FAIL); } }
HRESULT GenerateError (REFCLSID rClsId, REFIID riid, LPCOLESTR pcHelpFile, HRESULT hRes) { #endif CComBSTR strMsgLine; DWORD dwErr = FormatMessageLine( strMsgLine, hRes, NULL ); #if defined(_DEBUG) USES_CONVERSION; if( dwErr ) { LPTSTR lptMsg = NULL; CComBSTR strMsg(L"\n---------------------- Fehler beim Erzeugen der Fehlermeldung ----------------------\n"); if( ::FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_ALLOCATE_BUFFER, NULL, dwErr, 1024, (LPTSTR) &lptMsg, 0, NULL ) ) { USES_CONVERSION; strMsg.Append( A2W(lptMsg) ); ::LocalFree(lptMsg); if( 0x716 == dwErr ) { strMsg.Append(L"\n----------------------------------------------------------------------------------------"); strMsg.Append( L"\nHat die Message-Ressource den Wert 1? ;-)" ); } strMsg.Append(L"\n----------------------------------------------------------------------------------------"); _CrtDbgReport(_CRT_ASSERT, strFile, line, NULL, W2A(strMsg) ); return E_FAIL; } } CComBSTR strDbgLine; FormatDebuggerLine( strDbgLine, hRes, strFile, line, strExpr ); strDbgLine.Append( _T("\t") ); strDbgLine.Append( strMsgLine ); strDbgLine.Append( _T("\n") ); { ATLTRACE( W2A(strDbgLine) ); } #endif DWORD dwHelpID = hRes; return AtlReportError(rClsId, strMsgLine, dwHelpID, pcHelpFile, riid, hRes); }
STDMETHODIMP _ConfigurationPagesAdapter::get_Item(long index, IPropertyPage** pVal) { typedef CComObject<_ConfigurationPageAdapter> _ConfigurationPageAdapterComObject; try { _ConfigurationPageAdapterComObject* pResult = 0; HRESULT hr = _ConfigurationPageAdapterComObject::CreateInstance(&pResult); if(FAILED(hr)) throw Workshare::Com::ComException(_T("Failed to create an instance of _ConfigurationPageAdapter while adapting an ConfigurationPage (c++) to an _ConfigurationPage(com) when get_Item was called"), hr); ConnectorConfigurationPage& configPage = m_pConnectorConfigurationPages->GetAt(index); pResult->SetConfigurationPage(configPage); hr = pResult->QueryInterface(pVal); if(FAILED(hr)) { delete pResult; throw Workshare::Com::ComException(_T("Query interface failed to obtain a _ConfigurationPage from an instance of _ConfigurationPageAdapter"), hr); } return S_OK; } catch(Workshare::Exception const& e) { return AtlReportError(__uuidof(this), e.Message, __uuidof(_ConfigurationPages), e.ErrorCode); } catch(...) { return ProcessUnhandledException(); } }
STDMETHODIMP MailAttachments::get_Item(LONG index, IMailAttachment** pVal) { try { if(pVal == 0) throw Workshare::ArgumentNullException(_T("pVal"), _T("The return argument may not be null")); LONG upper = (LONG)m_Attachments.size(); if((index <= 0) || (index > upper)) throw Workshare::System::IndexOutOfRangeException(_T("The index is out of range [1-%d]"), upper); IUnknownPtr spUnk = m_Attachments.at(index-1); HRESULT hr = spUnk.QueryInterface(__uuidof(IMailAttachment), *pVal); if(FAILED(hr)) { std::tostringstream os; os << _T("Failed to query the IMailAttachment instance at index ") << index << std::ends; throw Workshare::Com::ComException(os.str().c_str(), hr, spUnk); } } catch(const Workshare::Exception& e) { return AtlReportError(__uuidof(this), e.Message, __uuidof(IMailAttachments), e.ErrorCode); } catch(...) { return ProcessUnhandledException(); } return S_OK; }
HRESULT CPigEngine::AddInvokeCommands(CPigBehaviorScriptType* pType) { // Get the collection of invoke commands for the new object XBehaviorMap mapCommands; ZSucceeded(GetInvokeCommands(pType, mapCommands)); // Iterate through each one and determine if it's already in the map XLock lock(this); for (XBehaviorMapIt it = mapCommands.begin(); it != mapCommands.end(); ++it) { XBehaviorMapIt itFind = m_mapBehaviors.find(it->first); if (m_mapBehaviors.end() != itFind) { pType->put_AppearsValid(VARIANT_FALSE); return AtlReportError(CLSID_PigSession, IDS_E_BEHAVIOR_INVCMD_REUSED, IID_IPigSession, 0, _Module.GetResourceInstance()); } } // Add each one from the local map to the main map for (XScriptMapIt it = mapCommands.begin(); it != mapCommands.end(); ++it) { m_mapBehaviors.insert(*it); it->second->AddRef(); } // Indicate success return S_OK; }
STDMETHODIMP Profile::put_FullName(BSTR newVal) { try { gSkypeQueue.SetProperty(L"PROFILE", L"", L"FULLNAME", newVal); return S_OK; } catch (const WCHAR * err) { return AtlReportError(GetObjectCLSID(), err, GUID_NULL, E_FAIL); } }
STDMETHODIMP Profile::put_VoicemailEnabled(VARIANT_BOOL newVal) { try { gSkypeQueue.SetProperty(L"PROFILE", L"", L"CALL_SEND_TO_VM", newVal ? L"TRUE" : L"FALSE"); return S_OK; } catch (const WCHAR * err) { return AtlReportError(GetObjectCLSID(), err, GUID_NULL, E_FAIL); } }
/* * Sends a command to the Maya command port. Connects to the command port * if not already connected. The result returned by Maya is stored as a * string in the m_strReply member variable, to be potentially processed * later by the get_Result() member function. * * Parameters * Command [in] Null-terminated string with the command. * * Return Value * Returns S_OK if successful, or an error value otherwise. * * Remarks * The return value from this method only indicates whether the command * was successfully sent to the Maya command port. It does not indicate * if the command was successfully executed by Maya. */ STDMETHODIMP CMELCommand::Execute(BSTR Command) { m_strResult.Empty(); HRESULT hr = Connect(); if (FAILED(hr)) return hr; // convert BSTR to ANSI CAtlString strCommand(Command); CW2A pszCommand(strCommand); // send command to Maya command port int err = send(m_socket, pszCommand, (int)strlen(pszCommand), 0); if (err == SOCKET_ERROR) { Disconnect(); return AtlReportError(GetObjectCLSID(), L"Unable to send command to command port", IID_IMELCommand); } // wait for reply, store result as raw string char* recvBuf = new char[4096+1]; int numBytes = recv(m_socket, recvBuf, 4096, 0); if (numBytes == SOCKET_ERROR) { delete[] recvBuf; Disconnect(); return AtlReportError(GetObjectCLSID(), L"Unable to get reply from command port", IID_IMELCommand); } recvBuf[numBytes] = '\0'; // practising safe string usage CA2W pszRecv(recvBuf); // convert ANSI to Unicode m_strResult = pszRecv; delete[] recvBuf; m_strResult.TrimLeft(L" \r\n"); // trim junk from beginning m_strResult.TrimRight(L" \r\n"); // ...and end return S_OK; }
STDMETHODIMP Profile::get_VoicemailEnabled(VARIANT_BOOL * pVal) { try { WCHAR * pResult = gSkypeQueue.RetrieveProperty(L"PROFILE", L"", L"CALL_SEND_TO_VM"); *pVal = (_wcsicmp(pResult, L"TRUE") == 0); free(pResult); return S_OK; } catch (const WCHAR * err) { return AtlReportError(GetObjectCLSID(), err, GUID_NULL, E_FAIL); } }
STDMETHODIMP Profile::get_NoAnswerTimeout(LONG* pVal) { try { WCHAR * pResult = gSkypeQueue.RetrieveProperty(L"PROFILE", L"", L"CALL_NOANSWER_TIMEOUT"); *pVal = _wtol(pResult); free(pResult); return S_OK; } catch (const WCHAR * err) { return AtlReportError(GetObjectCLSID(), err, GUID_NULL, E_FAIL); } }
STDMETHODIMP Profile::get_Timezone(LONG* pVal) { try { WCHAR * pResult = gSkypeQueue.RetrieveProperty(L"PROFILE", L"", L"TIMEZONE"); *pVal = _wtol(pResult); free(pResult); return S_OK; } catch (const WCHAR * err) { return AtlReportError(GetObjectCLSID(), err, GUID_NULL, E_FAIL); } }
STDMETHODIMP Profile::get_MoodText(BSTR* pVal) { try { WCHAR * pResult = gSkypeQueue.RetrieveProperty(L"PROFILE", L"", L"MOOD_TEXT"); *pVal = SysAllocString(pResult); free(pResult); return S_OK; } catch (const WCHAR * err) { return AtlReportError(GetObjectCLSID(), err, GUID_NULL, E_FAIL); } }
STDMETHODIMP Profile::put_NoAnswerTimeout(LONG newVal) { try { WCHAR wstrNumber[64]; _ltow_s(newVal, wstrNumber, sizeof(wstrNumber)/sizeof(wstrNumber[0]), 10); gSkypeQueue.SetProperty(L"PROFILE", L"", L"CALL_NOANSWER_TIMEOUT", wstrNumber); return S_OK; } catch (const WCHAR * err) { return AtlReportError(GetObjectCLSID(), err, GUID_NULL, E_FAIL); } }
STDMETHODIMP Profile::get_Sex(SkypeUserSex* pVal) { try { WCHAR * pResult = gSkypeQueue.RetrieveProperty(L"PROFILE", L"", L"SEX"); *pVal = TextToSkypeUserSex(pResult); free(pResult); return S_OK; } catch (const WCHAR * err) { return AtlReportError(GetObjectCLSID(), err, GUID_NULL, E_FAIL); } }
STDMETHODIMP CID3Frame::put_Compressed(VARIANT_BOOL newVal) { try { m_Frame->SetCompression(newVal == VARIANT_TRUE); return S_OK; } catch (...) { return AtlReportError(CLSID_ID3ComFrame, "An unexpected error has occurred", IID_IID3ComFrame, E_UNEXPECTED); } }
STDMETHODIMP CID3Frame::put_ID(eID3FrameTypes newVal) { try { m_Frame->SetID((ID3_FrameID)newVal); return S_OK; } catch (...) { return AtlReportError(CLSID_ID3ComFrame, "An unexpected error has occurred", IID_IID3ComFrame, E_UNEXPECTED); } }
STDMETHODIMP CID3Frame::Clear() { try { m_Frame->Clear(); return S_OK; } catch (...) { return AtlReportError(CLSID_ID3ComFrame, "An unexpected error has occurred", IID_IID3ComFrame, E_UNEXPECTED); } }
STDMETHODIMP MailAttachments::Add(BSTR filename, BSTR displayName, IMailAttachment** pReturnVal) { try { if(0 == filename) throw Workshare::ArgumentNullException(_T("filename"), _T("The filename may not be null.")); CString sFileName(filename); if(sFileName.IsEmpty()) throw Workshare::ArgumentException(_T("filename"), _T("The filename may not be empty.")); CPath path(sFileName); if(!path.FileExists()) throw Workshare::System::IO::FileNotFoundException(sFileName, _T("The file to be attached doesn't exist.")); if(pReturnVal == 0) throw Workshare::ArgumentNullException(_T("pReturnVal"), _T("The return argument may not be null.")); CComObject<MailAttachment>* pAttachment = NULL; HRESULT hr = CComObject<MailAttachment>::CreateInstance(&pAttachment); if(FAILED(hr)) throw Workshare::Com::ComException(_T("Failed to create an instance of Workshare.MailAttachment"), hr); hr = pAttachment->QueryInterface(pReturnVal); if(FAILED(hr)) { delete pAttachment; throw Workshare::Com::ComException(_T("Workshare.MailAttachment doesn't implement the IMailAttachment interface."), hr); } CString sDisplayName(displayName); if(sDisplayName.IsEmpty()) { sDisplayName = sFileName; int nPos = path.FindFileName(); sDisplayName.Delete(0, nPos); } pAttachment->SetFileName(sFileName); pAttachment->SetDisplayName(sDisplayName); m_Attachments.push_back(*pReturnVal); } catch(const Workshare::Exception& e) { return AtlReportError(__uuidof(this), e.Message, __uuidof(IMailAttachments), e.ErrorCode); } catch(...) { return ProcessUnhandledException(); } return S_OK; }
STDMETHODIMP Profile::put_Birthday(DATE newVal) { try { CDateTime dt = newVal; _bstr_t bstrDate = dt.Format("%Y%m%d"); gSkypeQueue.SetProperty(L"PROFILE", L"", L"BIRTHDAY", bstrDate); return S_OK; } catch (const WCHAR * err) { return AtlReportError(GetObjectCLSID(), err, GUID_NULL, E_FAIL); } }
STDMETHODIMP CID3Frame::get_ID(eID3FrameTypes *pVal) { try { *pVal = ID3_NOFRAME; *pVal = (eID3FrameTypes)m_Frame->GetID(); return S_OK; } catch (...) { return AtlReportError(CLSID_ID3ComFrame, "An unexpected error has occurred", IID_IID3ComFrame, E_UNEXPECTED); } }
////////////////////////////////////////////////// // Set X point value at point index STDMETHODIMP CGraphElement::put_XValue(/*[in]*/ long index, /*[in]*/ double newVal) { if(index < 0 || index > m_PointList.GetSize()) { return AtlReportError(CLSID_NULL, L"Point not found!", IID_NULL, E_INVALIDARG); } m_PointList[index].x = newVal; if(m_pCtrl) { m_pCtrl->Refresh(FALSE); } return S_OK; }
//////////////////////////////////////////////////// // Get Y point value at point index STDMETHODIMP CGraphElement::get_YValue(/*[in]*/ long index, /*[out, retval]*/ double* pVal) { if(index < 0 || index > m_PointList.GetSize()) { return AtlReportError(CLSID_NULL, L"Point not found!", IID_NULL, E_INVALIDARG); } if(pVal == nullptr) { return E_POINTER; } *pVal = m_PointList[index].y; return S_OK; }
//***************************************************************************** //* Function Name: ThrowComErrorException //* Description: //***************************************************************************** void ThrowComErrorException ( LPCTSTR p_lpszFile, UINT p_uLine, HRESULT p_hr, const _bstr_t& p_sbstrDescription) { USES_CONVERSION; CLSID l_clsid = GUID_NULL; IID l_iid = GUID_NULL; CActiveMethodGUIDs::Get (l_clsid, l_iid); // AtlReportError() creates and populates a standard COM error object // and calls SetErrorInfo() to pass the COM error object to the COM // run-time. (void) AtlReportError ( l_clsid, // rclsid p_sbstrDescription.operator LPCOLESTR (), // lpszDesc l_iid, // riid p_hr); // hRes // At this point, the COM run-time has the only reference to the error object. IErrorInfoPtr l_spErrorInfo; // From MSDN re GetErrorInfo(): // // "This function returns a pointer to the most recently set IErrorInfo // pointer in the current logical thread. It transfers ownership of the // error object to the caller, and clears the error state for the thread." if (SUCCEEDED (::GetErrorInfo (0 /* dwReserved */, &l_spErrorInfo))) { // At this point, the COM run-time's reference to the error object has // been transferred to l_spErrorInfo. Specify true for the last parameter // of the _com_error constructor to make sure that it calls AddRef() on // the error object. This last parameter is optional and defaults to // false. If true is *not* specified then the _com_error constructor // won't call AddRef() so the only reference will be the one in // l_spErrorInfo which will be released when l_spErrorInfo goes out of // scope i.e. when the _com_error exception is thrown. This will result // in the error object being prematurely destroyed. By passing true, // the only outstanding reference to the error object will be inside // the _com_error exception object which is as it should be. throw _com_error (p_hr, l_spErrorInfo, true /* fAddRef */); } // There was no rich error information so just use the HRESULT. throw _com_error (p_hr); }
HRESULT CPigEngine::put_LobbyMode(PigLobbyMode eMode) { // 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()); // Fail if an invalid mode is specified if (PigLobbyMode_Club > eMode || eMode > PigLobbyMode_Free) return AtlReportError(CLSID_PigSession, IDS_E_LOBBYMODE_UNSUPPORTED, IID_IPigSession, 0, _Module.GetResourceInstance()); // Open the registry key of the AppID CRegKey key; RETURN_FAILED(_Module.OpenAppIDRegKey(key)); // Save the specified lobby mode to the registry long lr = key.SetValue(static_cast<DWORD>(eMode), TEXT("LobbyMode")); if (ERROR_SUCCESS != lr) return HRESULT_FROM_WIN32(lr); // Save the specified lobby mode m_eLobbyMode = eMode; // Indicate success return S_OK; }
HRESULT CPigEngine::put_AccountServer(BSTR bstrServer) { // 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; long lr = key.SetValue(BSTRLen(bstrServer) ? OLE2CT(bstrServer) : TEXT(""), TEXT("AccountServer")); if (ERROR_SUCCESS != lr) return HRESULT_FROM_WIN32(lr); // Save the string m_bstrAccountServer = bstrServer; // Indicate success return S_OK; }