VC2008/2005工程自动生成器

本文介绍了一款简单的工具,该工具能够扫描指定目录及其子目录中的所有文件,并生成适用于Visual Studio 2008 IDE的XML工程文件。通过这个工具,开发者可以轻松地将未包含在任何现有工程中的源代码整合到VS2008环境中。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

 我很喜欢使用VS2008的IDE环境,但是很多源代码都没有可以用于Visual studio IDE的工程文件,例如DDK的示例代码.

于是我写了下面的工具,功能如下:

1.扫描指定目录并递归其子目录的所有文件,生成一个xml的VCMakeTool类型的工程文件.

使用方法:

  1.   usage:
  2.             buildvcproj dir destfilename
  3.   example:
  4.             buildvcproj c://abc abc.xml

源代码如下, 非常简单,贴出来,是希望有同样需要的朋友不用重复劳动.

// buildvcproj.cpp : 定义控制台应用程序的入口点。
//

#include "stdafx.h"
#include <windows.h>



FILE *g_pFile=NULL;
const char *g_packsDir=NULL;
int       g_packsDirLen=0;

void Build(const char *packsDir, const char *subdir)
{
    WIN32_FIND_DATAA FindFileData;
    HANDLE hFind = INVALID_HANDLE_VALUE;
    char DirSpec[MAX_PATH];  // directory specification
    DWORD dwError;
    strcpy(DirSpec,packsDir);
    
    int rlen = strlen(DirSpec);
    if(DirSpec[rlen -1]=='//')
    {
        DirSpec[rlen-1]='0';
    }

    if(subdir&&subdir[0]!=0)
    {
        strcat(DirSpec,"//");
        strcat(DirSpec,subdir);
    }

    int saveLen = strlen(DirSpec);
    
    strcat(DirSpec,"//*");      

    
    hFind = FindFirstFileA(DirSpec, &FindFileData);

    DirSpec[saveLen]='/0';

    if (hFind != INVALID_HANDLE_VALUE) 
    {
        do
        {
            if(FindFileData.dwFileAttributes&FILE_ATTRIBUTE_DIRECTORY )
            {
                if(FindFileData.cFileName[0]!='.' 
                    && strstr(FindFileData.cFileName,"objchk")==NULL
                    && strstr(FindFileData.cFileName,"objfre")==NULL
                    )

                {
                    fprintf(g_pFile,"   <Filter "
                    "/nName=/"%s/""
                    "/nFilter=/"cpp;c;h;cc;cxx;def;odl;idl;hpj;bat;asm;asmx/""
                    "/n>/n",FindFileData.cFileName
                    );
                    Build(DirSpec,FindFileData.cFileName);
                    fprintf(g_pFile,"%s/n","/n  </Filter>/n");
                }
            }
            else
            {
                int len =strlen(FindFileData.cFileName);
                if(len<4 || strcmpi(FindFileData.cFileName+len-4,".obj")!=0)
                {
                    fprintf(g_pFile,
                    "/n<File"
                    "/nRelativePath=/".%s//%s/""
                    "/n></File>/n",
                    DirSpec+g_packsDirLen,FindFileData.cFileName);
                }
                
            }

            
        }
        while (FindNextFileA(hFind, &FindFileData) != 0) ;

        dwError = GetLastError();
        FindClose(hFind);
    }


}



int _tmain(int argc, _TCHAR* argv[])
{

    if(argc<3)
    {
        printf("usage:/nbuildvcproj dir destfilename/n"
            "example:/n"
            "buildvcproj c://abc abc.xml/n");
        return 0;
    }



    g_pFile=fopen(argv[2],"w");
    if(g_pFile)
    {
        fprintf(g_pFile,"%s",
                            "<?xml version=/"1.0/" encoding=/"gb2312/"?>"
                            "/n<VisualStudioProject"
                            "/n ProjectType=/"Visual C++/""
                            "/n Version=/"9.00/""
                            "/n Name=/"win2ksrc/""
                            "/n ProjectGUID=/"{8B8C6959-68F6-4182-8EA9-87C1E30EBE9E}/""
                            "/n Keyword=/"MakeFileProj/""
                            "/n TargetFrameworkVersion=/"196613/""
                            "/n >"
                            "/n <Platforms>"
                            "/n     <Platform"
                            "/n         Name=/"Win32/""
                            "/n     />"
                            "/n </Platforms>"
                            "/n <ToolFiles>"
                            "/n </ToolFiles>"
                            "/n <Configurations>"
                            "/n     <Configuration"
                            "/n         Name=/"Debug|Win32/""
                            "/n         OutputDirectory=/"$(ConfigurationName)/""
                            "/n         IntermediateDirectory=/"$(ConfigurationName)/""
                            "/n         ConfigurationType=/"0/""
                            "/n         >"
                            "/n         <Tool"
                            "/n             Name=/"VCNMakeTool/""
                            "/n             BuildCommandLine=/"/""
                            "/n             ReBuildCommandLine=/"/""
                            "/n             CleanCommandLine=/"/""
                            "/n             Output=/"win2ksrc.exe/""
                            "/n             PreprocessorDefinitions=/"WIN32;_DEBUG/""
                            "/n             IncludeSearchPath=/"/""
                            "/n             ForcedIncludes=/"/""
                            "/n             AssemblySearchPath=/"/""
                            "/n             ForcedUsingAssemblies=/"/""
                            "/n             CompileAsManaged=/"/""
                            "/n         />"
                            "/n     </Configuration>"
                            "/n     <Configuration"
                            "/n         Name=/"Release|Win32/""
                            "/n         OutputDirectory=/"$(ConfigurationName)/""
                            "/n         IntermediateDirectory=/"$(ConfigurationName)/""
                            "/n         ConfigurationType=/"0/""
                            "/n         >"
                            "/n         <Tool"
                            "/n             Name=/"VCNMakeTool/""
                            "/n             BuildCommandLine=/"/""
                            "/n             ReBuildCommandLine=/"/""
                            "/n             CleanCommandLine=/"/""
                            "/n             Output=/"win2ksrc.exe/""
                            "/n             PreprocessorDefinitions=/"WIN32;NDEBUG/""
                            "/n             IncludeSearchPath=/"/""
                            "/n             ForcedIncludes=/"/""
                            "/n             AssemblySearchPath=/"/""
                            "/n             ForcedUsingAssemblies=/"/""
                            "/n             CompileAsManaged=/"/""
                            "/n         />"
                            "/n     </Configuration>"
                            "/n </Configurations>"
                            "/n <References>"
                            "/n </References>"
                            "/n <Files>"
                            "/n "
                            );
        g_packsDir=argv[1];
        g_packsDirLen= strlen(g_packsDir);
        Build(g_packsDir,"");
        fprintf(g_pFile,"%s",
                            "/n </Files>"
                            "/n <Globals>"
                            "/n </Globals>"
                            "/n</VisualStudioProject>"
                            );


        fclose(g_pFile);
    }
    else
    {
        printf("Can not open file %s/n",argv[2]);
    }

    return 0;
}

评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值