⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 compliervc60.cpp

📁 自动化编译工具代码
💻 CPP
字号:
// ComplierVC60.cpp: implementation of the CComplierVC60 class.
//
//////////////////////////////////////////////////////////////////////

#include "stdafx.h"
#include "ComplierVC60.h"

#include <atlbase.h>
#include "Common.h"

#ifdef _DEBUG
#undef THIS_FILE
static char THIS_FILE[]=__FILE__;
#define new DEBUG_NEW
#endif

//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////

CComplierVC60::CComplierVC60()
{
	HRESULT hr = m_pApp.CreateInstance("MSDEV.Application");
	ASSERT(SUCCEEDED(hr));
	m_pApp->PutActive(FALSE);
}

CComplierVC60::~CComplierVC60()
{
	//If $projectname$.opt is not exist, MSDEV will pop a Message.
	//The programe is not to be automatism.
	const CString strOutFile = CCommon::GetFilePath(m_strProjectFile) 
							 + CCommon::GetFileName(m_strProjectFile) + ".opt";
	if (!CFileFind().FindFile(strOutFile))
	{
		CCommon::CreateEmptyFile(strOutFile);
	}
	HRESULT hr = m_pApp->Quit();
}

BOOL CComplierVC60::Build(const CString &strProjectFile,
						  const CString &strConfigName,
						  const CString &strOutputFile)
{
	if (!CFileFind().FindFile(strProjectFile))
		return FALSE;
	m_strProjectFile = strProjectFile;
	BOOL bResult = TRUE;

	IDocumentsPtr pDocs = m_pApp->GetDocuments();
	HRESULT hr = pDocs->Open(_bstr_t(strProjectFile), CComVariant("Auto"), CComVariant("False"));
	if (FAILED(hr))		
		return FALSE;

	IProjectsPtr pProjects = m_pApp->GetProjects();
	ASSERT(pProjects != NULL);

	for (int i = 1; i <= pProjects->GetCount(); i++)
	{
		IBuildProjectPtr	pBuildProject = pProjects    ->Item(CComVariant(i));
		IConfigurationsPtr  pConfigs	  = pBuildProject->GetConfigurations();

		for (int j = 1; j <= pConfigs->GetCount(); j++)
		{
			IConfigurationPtr pConfig = pConfigs->Item(CComVariant(j));
			
			CString strConfigJJJ  = pConfig->GetName().copy(); 
			strConfigJJJ.MakeLower();
			CString strConfigNameLower = strConfigName;
			strConfigNameLower.MakeLower();
			if (strConfigJJJ.Find(strConfigNameLower) != -1)
			{
				if (!strOutputFile.IsEmpty())	// Set output file path
				{
					_bstr_t varTool   = "link.exe";
					//----->    /out:"Debug1/TT.exe"   <-----
					CString strT;		strT.Format(CString("/out:\"%s\""), strOutputFile);
					_bstr_t varSwitch = strT.AllocSysString();
					pConfig->AddToolSettings(varTool, varSwitch, CComVariant(j));
				}
				bResult = SUCCEEDED(m_pApp->Build(pConfig.GetInterfacePtr())) && bResult;
			}
		}
	}
	
	return bResult;	
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -