HRESULT vsnet_addin::GetActiveProject(EnvDTE::ProjectPtr& pProj) { EnvDTE::DocumentPtr pCurDoc; m_pDTE->get_ActiveDocument(&pCurDoc); if (pCurDoc != NULL) { EnvDTE::ProjectItemPtr pProjItem; pCurDoc->get_ProjectItem(&pProjItem); if (pProjItem == NULL) { return S_FALSE; } return pProjItem->get_ContainingProject(&pProj); } else { _variant_t vt, vt2; if (FAILED(m_pDTE->get_ActiveSolutionProjects(&vt))) { return S_FALSE; } if (vt.vt != (VT_ARRAY | VT_VARIANT)) { return S_FALSE; } SAFEARRAY* pArray = vt.parray; if (pArray->cDims != 1 && !(pArray->fFeatures & FADF_DISPATCH )) { return S_FALSE; } if (pArray[0].rgsabound[0].cElements > 0) { vt2 = ((_variant_t*)pArray[0].pvData)[0]; pProj = vt2.pdispVal; if (pProj == NULL) { return S_FALSE; } } else return S_FALSE; } return S_OK; }
HRESULT vsnet_addin::GetSelectedProject(EnvDTE::ProjectPtr& pProj) { EnvDTE::SelectedItemsPtr pSelItems; if (m_pDTE->get_SelectedItems(&pSelItems) == S_OK) { ATLASSERT(pSelItems != NULL); long Count; pSelItems->get_Count(&Count); if (Count) { EnvDTE::SelectedItemPtr pSelItem; pSelItems->Item(_variant_t(1), &pSelItem); ATLASSERT(pSelItem != NULL); EnvDTE::ProjectItemPtr pProjItem; pSelItem->get_ProjectItem(&pProjItem); if (pProjItem != NULL) { return pProjItem->get_ContainingProject(&pProj); } } } return E_FAIL; }
bool CDDXManager::CheckCString(VSClass* pClass) { EnvDTE::ProjectPtr pProject; EnvDTE::ProjectItemPtr pProjectItem; EnvDTE::GlobalsPtr pProjGlobals; pClass->pElement->get_ProjectItem(&pProjectItem); pProjectItem->get_ContainingProject(&pProject); pProject->get_Globals(&pProjGlobals); if (pProjGlobals != NULL) { VARIANT_BOOL bExist; pProjGlobals->get_VariableExists(_bstr_t(L"CTypeCString.Ask"), &bExist); if (bExist == VARIANT_TRUE) return true; } if (FindInclude(pClass, L"<atlstr.h>", true) != NULL || FindInclude(pClass, L"<atlmisc.h>", true) != NULL) { return true; } CSmartAtlArray<InsertionPoint*>& CurInsPoints = m_pModifications->InsertPoints; for (size_t i = 0; i < CurInsPoints.GetCount(); i++) { if (CurInsPoints[i]->Type == INSERT_POINT_INCLUDE) { InsertInclude* pInsInclude = (InsertInclude*)CurInsPoints[i]; if (pInsInclude->pElement->Name == _T("<atlstr.h>") || pInsInclude->pElement->Name == _T("<atlmisc.h>")) { return true; } } } ATLASSERT(m_pGlobalModifications); for (size_t i = 0; i < m_pGlobalModifications->GetCount(); i++) { CSmartAtlArray<InsertionPoint*>& InsPoints = (*m_pGlobalModifications)[i].InsertPoints; for (size_t j = 0; j < InsPoints.GetCount(); j++) { if (InsPoints[j]->Type == INSERT_POINT_INCLUDE) { InsertInclude* pInsInclude = (InsertInclude*)InsPoints[j]; if (pInsInclude->pProjectFile != NULL) { if (pInsInclude->pElement->Name == _T("<atlstr.h>") || pInsInclude->pElement->Name == _T("<atlmisc.h>")) { return true; } } } } } //показать диалог в котором можно будет выбрать CString используемый CTypeCStringDlg dlg; EnvDTE::ProjectItemPtr pStdAfxFile = FindItem(pProject, _bstr_t(L"stdafx.h"), EnvDTE::ProjectItemPtr(NULL)); if (pStdAfxFile != NULL) { dlg.m_bStdAfx = true; } else { dlg.m_bStdAfx = false; } if (dlg.DoModal() == IDOK) { if (dlg.m_Type == STYPE_ANOTHER) return true; if (dlg.m_Type == STYPE_WTL) { InsertWtlCString(pProject, CurInsPoints, dlg.m_Place); return true; } if (dlg.m_Type == STYPE_ATL) { InsertAtlCString(pProject, CurInsPoints); } if (dlg.m_bAskAgain) { pProjGlobals->put_VariablePersists(_bstr_t(L"CTypeCString.Ask"), VARIANT_TRUE); } } return true; }