void CPagePlayers::PopulatePlayersList() { CWaitCursor wait; LPCSTR pszContext = "retrieving collection of players in game"; // Clear the contents of the list m_listPlayers.DeleteAllItems(); // Do nothing else if there is no game in progress if (NULL == GetSheet()->GetGame()) return; // Get the collection of users in the game IAdminUsersPtr spUsers; HRESULT hr = GetSheet()->GetGame()->get_Users(&spUsers); if (FAILED(hr)) { GetSheet()->HandleError(hr, pszContext, true); return; } // Get the enumerator object from the collection IUnknownPtr spEnumUnk; if (FAILED(hr = spUsers->get__NewEnum(&spEnumUnk))) { GetSheet()->HandleError(hr, pszContext, true); return; } IEnumVARIANTPtr spEnum(spEnumUnk); if (NULL == spEnum) { GetSheet()->HandleError(E_NOINTERFACE, pszContext, true); return; } // Iterate through each player from the enumerator int iIndex = 0; CComVariant players[32]; do { // Fetch the next block of players from the enumerator ULONG cFetched; if (FAILED(hr = spEnum->Next(sizeofArray(players), players, &cFetched))) { GetSheet()->HandleError(hr, pszContext, true); return; } // Add each player to the list for (ULONG i = 0; i < cFetched; ++i) { // Convert the VARIANT to IDispatch, if not already VARTYPE vt = V_VT(&players[i]); if (VT_DISPATCH != vt && VT_UNKNOWN != vt) { GetSheet()->HandleError(DISP_E_TYPEMISMATCH, pszContext, true); return; } // Ensure that the IDispatch supports IAdminUser IAdminUserPtr spUser(V_DISPATCH(&players[i])); if (NULL == spUser) { GetSheet()->HandleError(E_NOINTERFACE, pszContext, true); return; } // Clear the VARIANT in the array players[i].Clear(); // Get the ship object of the user IAdminShipPtr spShip; if (FAILED(hr = spUser->get_Ship(&spShip))) { GetSheet()->HandleError(hr, pszContext, true); return; } // Get the interesting properties of the User CComBSTR bstrName, bstrTeam, bstrSector; // Model Name spShip->get_Name(&bstrName); // Team IAGCTeamPtr spTeam; spShip->get_Team(&spTeam); if (NULL != spTeam) spTeam->get_Name(&bstrTeam); // Sector IAGCSectorPtr spSector; spShip->get_Sector(&spSector); if (NULL != spSector) spSector->get_Name(&bstrSector); // Add the ship to the list USES_CONVERSION; m_listPlayers.InsertItem(iIndex, OLE2CT(bstrName)); m_listPlayers.SetItemText(iIndex, c_iColumnTeam, OLE2CT(bstrTeam)); m_listPlayers.SetItemText(iIndex, c_iColumnSector, OLE2CT(bstrSector)); m_listPlayers.SetItemData(iIndex, reinterpret_cast<DWORD>(spShip.Detach())); ++iIndex; } } while (S_FALSE != hr); }
STDMETHODIMP CIndexAtom::InitBasketDivs(IUndColl* pUndColl) { ObjectLock lock(this); m_spDivs->Clear(); //if(VARIANT_FALSE != m_bIsBasket) { if(pUndColl != NULL) { try { IUndCollPtr spUndColl(pUndColl); IUndAtomPtr spUnd = NULL; IIndexCompAtomPtr spIdxComp = NULL; _variant_t varItem; ULONG nFetched = 0L; LONG nID = 0L; DOUBLE dWeight = 0.0; EtsContractTypeEnum enUndType; EtsDivTypeEnum enDivType(enDivMarket); VARIANT_BOOL bValidDivs(VARIANT_FALSE); IEtsDivCollPtr spCustDivs = NULL; IEtsIndexDivAtomPtr spNewDividend = NULL; IEtsIndexDivAtomPtr spUndDividend = NULL; IEtsIndexDivAtomPtr spRetDividend = NULL; HRESULT hr = S_OK; IUnknownPtr spUnk = NULL; _CHK(m_spComponents->get__NewEnum(&spUnk), _T("Fail to get index components collection.")); IEnumVARIANTPtr spEnum(spUnk); if (spEnum != NULL) { _CHK(spEnum->Reset(), _T("Fail to reset index components collection.")); while((hr = spEnum->Next(1L, &varItem, &nFetched)) == S_OK) { ATLASSERT(varItem.vt == VT_DISPATCH); spIdxComp = varItem; if(nFetched > 0L && spIdxComp != NULL) { nID = 0L; dWeight = 0.0; _CHK(spIdxComp->get_Weight(&dWeight), _T("Fail to get index component weight.")); _CHK(spIdxComp->get_ID(&nID), _T("Fail to get index component ID.")); if(dWeight > 0.) { spUnd = NULL; _CHK(spUndColl->get_Item(nID, &spUnd), _T("Fail to get component underlying.")); if(spUnd != NULL) { enUndType = enCtStock; _CHK(spUnd->get_UndType(&enUndType), _T("Fail to get component underlying type.")); if(enUndType = enCtStock) { spNewDividend = NULL; spUndDividend = NULL; spRetDividend = NULL; spUnd->get_Dividend(&spUndDividend); if (spUndDividend != NULL) { LONG lIndex = 0; m_spDivs->get_Count(&lIndex); _CHK(m_spDivs->Add(lIndex, lIndex, spUndDividend, &spNewDividend), _T("Fail add dividends to collection")); _CHK(m_spDivs->SetWeight(lIndex, dWeight)); } } spUnd = NULL; } } } spIdxComp = NULL; varItem.Clear(); } } _CHK(hr, _T("Fail to get next index component.")); } catch(const _com_error& e) { m_spDivs->Clear(); return Error((PTCHAR)EgLib::CComErrorWrapper::ErrorDescription(e), IID_IIndexAtom, e.Error()); } } else { return Error(L"Invalid underlying collection.", IID_IIndexAtom, E_INVALIDARG); } } return S_OK; }
bool DominoConnector::GetInfoFromFileName(const std::wstring& fileName, std::wstring& repositoryId, std::wstring& artifactId, std::wstring& artifactVersionLabel) { USES_CONVERSION; if(!PathFileExistsW(fileName.c_str())) throw Workshare::System::IO::FileNotFoundException(fileName.c_str(), _T("The filename must exist in order to extract Lotus Domino.Doc information from the document")); DWORD grfMode = STGM_READWRITE | STGM_SHARE_EXCLUSIVE; IStorage* pStorage = NULL; HRESULT hr = ::StgOpenStorage(fileName.c_str(), NULL, grfMode, NULL, 0, &pStorage); switch(hr) { case S_OK: break; case STG_E_LOCKVIOLATION: case STG_E_SHAREVIOLATION: case STG_E_ACCESSDENIED: { ILockBytesPtr spLockBytes(ReadFileIntoMemory(fileName.c_str()), false); hr = ::StgOpenStorageOnILockBytes(spLockBytes, NULL, STGM_READWRITE | STGM_SHARE_EXCLUSIVE, NULL, 0, &pStorage); if(FAILED(hr)) { std::tostringstream msg; msg << _T("The file, [") << fileName.c_str() << _T("], has been locked. An attempt was made to read it into memory (into an instance of ILockBytes) and open a storage from there, but that failed too.") << std::ends; throw Workshare::Com::ComException(msg.str().c_str(), hr); } } break; default: { std::tostringstream msg; msg << _T("Failed to open [") << fileName.c_str() << _T("] using StgOpenStorage while checking to see whether the document has Domino.Doc properties or not.") << std::ends; throw Workshare::Com::ComException(msg.str().c_str(), hr); } break; } IStoragePtr spStorage(pStorage, false); IPropertySetStoragePtr spPropertySetStorage(spStorage); IPropertyStorage* pPropertyStorage = NULL; hr = spPropertySetStorage->Open(FMTID_UserDefinedProperties, grfMode, &pPropertyStorage); if(FAILED(hr)) { Log(_T("Failed to open the custom properties storage from [%S] while trying to determine whether its a Domino.Doc document or not."), fileName.c_str()); return false; } IPropertyStoragePtr spPropertyStorage(pPropertyStorage, false); IEnumSTATPROPSTG *pEnumSTATPROPSTG = NULL; hr = spPropertyStorage->Enum(&pEnumSTATPROPSTG); if(FAILED(hr)) { std::tostringstream msg; msg << _T("Failed to obtain an enumeration for the custom properties of [") << fileName.c_str() << _T("] while checking to see whether the document has Domino.Doc properties or not.") << std::ends; throw Workshare::Com::ComException(msg.str().c_str(), hr); } IEnumSTATPROPSTGPtr spEnum(pEnumSTATPROPSTG, false); bool isDominoDocument = false; STATPROPSTG property; hr = spEnum->Next(1, &property, NULL); while(S_OK == hr) { PROPSPEC specification; PROPVARIANT value; PropVariantInit(&value); try { // Build a PROPSPEC for this property. ZeroMemory(&specification, sizeof(specification)); specification.ulKind = PRSPEC_PROPID; specification.propid = property.propid; hr = spPropertyStorage->ReadMultiple(1, &specification, &value); if(FAILED(hr)) { std::tostringstream msg; msg << _T("Failed to read the property with id [") << property.propid << _T("] from the custom properties of [") << fileName.c_str() << _T("] while checking to see whether the document has Domino.Doc properties or not.") << std::ends; throw Workshare::Com::ComException(msg.str().c_str(), hr); } if(value.vt == VT_LPSTR) { if(0 == lstrcmpiW(property.lpwstrName, L"DDocLibrary")) { isDominoDocument = true; repositoryId = A2W(value.pszVal); } else if(0 == lstrcmpiW(property.lpwstrName, L"DDocRevision")) { isDominoDocument = true; artifactVersionLabel = A2W(value.pszVal); } else if(0 == lstrcmpiW(property.lpwstrName, L"DDocID")) { isDominoDocument = true; artifactId = A2W(value.pszVal); } } else if(value.vt == VT_LPWSTR) { if(0 == lstrcmpiW(property.lpwstrName, L"DDocLibrary")) { isDominoDocument = true; repositoryId = value.pwszVal; } else if(0 == lstrcmpiW(property.lpwstrName, L"DDocRevision")) { isDominoDocument = true; artifactVersionLabel = value.pwszVal; } else if(0 == lstrcmpiW(property.lpwstrName, L"DDocID")) { isDominoDocument = true; artifactId = value.pwszVal; } } PropVariantClear(&value); } catch(...) { //TODO: Do we need to deal with failure to free a resource? PropVariantClear(&value); throw; } hr = spEnum->Next(1, &property, NULL); } return isDominoDocument; }