Visual Studio Developer Center >
Visual Studio Forums
>
Visual Studio Extensibility
>
Getting the VCProjectEngine in a C++ Package
Getting the VCProjectEngine in a C++ Package
- I'm working on a package for VS2005 written in C++, and am having trouble getting an instance of the VCProjectEngine object. I *think* something like the following should work, but QueryCachedService is failing with E_NOINTERFACE. Here's the command handler. It's the only thing I've customized in a wizard-generated package:
#include "StdAfx.h" #include "Package.h" //#import <VCProjectEngine.dll> rename ("PropertySheet", "VCPropertySheetX") #import "C:\Program Files\Microsoft Visual Studio 8\VC\vcpackages\VCProject.dll" raw_interfaces_only raw_native_types #import "C:\Program Files\Microsoft Visual Studio 8\VC\vcpackages\VCProjectEngine.dll" raw_interfaces_only raw_native_types rename("PropertySheet", "__PropertySheet") using namespace VCProjectEngineLibrary; // Command handler called when the user selects the "My Command" command. void CVSAnnotationPackage::OnMyCommand(CommandHandler* /*pSender*/, DWORD /*flags*/, VARIANT* /*pIn*/, VARIANT* /*pOut*/) { HRESULT hr; CComPtr<VCProjectEngine> spEngine; hr = this->GetVsSiteCache().QueryCachedService<VCProjectEngine, __uuidof(VCProjectEngine)>(&spEngine); if( FAILED( hr ) || !spEngine ) { OutputDebugString (L"Failed to create VCProjectEngine!\n"); return; } // Get the collection of VC Projects CComPtr<IDispatch> spDispProjects; hr = spEngine->get_Projects(&spDispProjects); CComQIPtr<IVCCollection> spCollProjects = spDispProjects; LONG nProjects; hr = spCollProjects->get_Count (&nProjects); }
Answers
- Hi Barry,
I don't think the VCProjectEngine is surfaced as a global service. But you should be able to retrieve the VCProject easily enough, given you have an IVsProject. The object that implements IVsProject also implements IVsHierarchy. Cast that interface to an IVsHierarchy, and try calling IVsHierarchy.GetProperty with VSITEMID_ROOT and VSHPROPID_ExtObject. This returns the IDispatch interface correlates to the EnvDTE.Project interface. From there you should be able to cast the Project.Object property to a VCProject interface.
Sincerely,
Ed Dore- Marked As Answer byWesley YaoMSFT, ModeratorMonday, October 26, 2009 4:03 AM
- Proposed As Answer byEd DoreMSFT, ModeratorWednesday, October 21, 2009 2:56 AM
All Replies
- P.S. If I can get from an IVsProject to a VCProject, that would also solve my problem. But I don't see any way to get there from here...
Thanks for the help.
- Barry - Hi Barry,
I don't think the VCProjectEngine is surfaced as a global service. But you should be able to retrieve the VCProject easily enough, given you have an IVsProject. The object that implements IVsProject also implements IVsHierarchy. Cast that interface to an IVsHierarchy, and try calling IVsHierarchy.GetProperty with VSITEMID_ROOT and VSHPROPID_ExtObject. This returns the IDispatch interface correlates to the EnvDTE.Project interface. From there you should be able to cast the Project.Object property to a VCProject interface.
Sincerely,
Ed Dore- Marked As Answer byWesley YaoMSFT, ModeratorMonday, October 26, 2009 4:03 AM
- Proposed As Answer byEd DoreMSFT, ModeratorWednesday, October 21, 2009 2:56 AM
- Thanks Ed. I'll give that a try.
- Barry - P.S. I worked around this problem by getting the DTE and using the automation objects. Is there any reason to go back to traversing the hierarchy instead?
- Barry - Thanks Ed. That did it. It's a pity there isn't a more direct path from the IVsHierarchy object to the VCProject.
- Barry


