星期六去了一趟海龙,内存终于升G了,下午回来看了一会儿.NET的msdn帮助,发现
DTE,觉得对大团队自动化编译很有利用价值了,就想写点东西出来!
通过这个接口很容易实现VC7的工程编译自动化,什么也不说了, 一切尽在代码中!
MSDN中描述DTE结构的示意图如下:
VC7.1的代码如下:
#pragma warning( disable : 4278 )
//The following #import imports DTE based on its LIBID
#import "libid:80cc9f66-e7d8-4ddd-85b6-d9e6cd0e93e2" version("7.0") lcid("0") raw_interfaces_only named_guids
#pragma warning( default : 4278 )
using namespace EnvDTE; // optional
//……
void Ct3Dlg::OnBnClickedOk()
{
CoInitialize(NULL);
{
_variant_t varRelease=L"Release";
_bstr_t bstrSlnPath=L"C:\\test\\W3\\W3.sln";
try
{
CComPtr<EnvDTE::_DTE> pZFIVE5_DTE;
_Solution *pZFIVE5_S=NULL;
SolutionBuild *pZFIVE5_SB=NULL;
SolutionConfigurations *pZFIVE5_SCs=NULL;
SolutionConfiguration *pZFIVE5_SC=NULL;
pZFIVE5_DTE.CoCreateInstance(L"VisualStudio.DTE.7.1", 0);
pZFIVE5_DTE->get_Solution(&pZFIVE5_S);
if(pZFIVE5_S==NULL)
{
pZFIVE5_DTE->Quit();
goto ZFive5ComRet;
}
pZIVE5_S->Open(bstrSlnPath);
VARIANT_BOOL var;
pZFIVE5_S->get_IsOpen(&var);
if (var==VARIANT_TRUE)
{
pZFIVE5_S->get_SolutionBuild(&pZFIVE5_SB);
if(pZFIVE5_SB==NULL)
{
pZFIVE5_S->Release();
pZFIVE5_S=NULL;
pZFIVE5_DTE->Quit();
goto ZFive5ComRet;
}
pZFIVE5_SB->get_SolutionConfigurations(&pZFIVE5_SCs);
if(pZFIVE5_SCs==NULL)
{
pZFIVE5_SB->Release();
pZFIVE5_SB=NULL;
pZFIVE5_S->Release();
pZFIVE5_S=NULL;
pZFIVE5_DTE->Quit();
goto ZFive5ComRet;
}
pZFIVE5_SCs->Item(varRelease,&pZFIVE5_SC);
if(pZFIVE5_SC!=NULL)
{
pZFIVE5_SC->Activate();
pZFIVE5_SC->Release();
pZFIVE5_SC=NULL;
}