怎么在C程序代码前加上程序版本,作者什么的

怎么在C程序代码前加上程序版本,作者什么的,第1张

版本信息可以写在注释里,既不影响程序,又能让人看到

/***********************************

**版本:1.0

**作者:***

***********************************/

注意c语言中注释是/*注释内容*/这种格式的,所以只能有一个*/和/*配对,c中注释不能嵌套,即

/*

.........

/*

......

*/

*/

这样就会编译错了,c编译器把倒数第二个*/和第一个/*配对,就会多出一个*/,为什么/*后面又跟了个/*不会编译错呢,是因为c中碰到/*就会去找第一个*/,碰到了c编译器就认为注释结束了

若要使用 Visual c + + 编辑器中,单击文件菜单上的打开,并在 MyProject.rc 文件打开方式列表中选择文本。在MyProject.rc 中找到的版本资源语句。它应如下所示://///////////////////////////////////////////////////////////////////// // // Version // VS_VERSION_INFO VERSIONINFO FILEVERSION 1,0,0,1 PRODUCTVERSION 1,0,0,1 FILEFLAGSMASK 0x3fL #ifdef _DEBUG FILEFLAGS 0x1L #else FILEFLAGS 0x0L #endif FILEOS 0x4L FILETYPE 0x1L FILESUBTYPE 0x0L BEGIN BLOCK "StringFileInfo" BEGIN BLOCK "040904b0" BEGIN VALUE "Comments", "Sample Application\0" VALUE "CompanyName", "Microsoft Corp.\0" VALUE "FileDescription", "MyProject MFC Application\0" VALUE "FileVersion", "1, 0, 0, 1\0" VALUE "InternalName", "MyProject\0" VALUE "LegalCopyright", "Copyright (C) 1999\0" VALUE "OriginalFilename", "MyProject.EXE\0" VALUE "ProductName", "MyProject Application\0" VALUE "ProductVersion", "1, 0, 0, 1\0" END END BLOCK "VarFileInfo" BEGIN VALUE "Translation", 0x409, 1200 END END 剪切从 MyProject.rc 文件版本资源并将其粘贴到一则评语下面的 MyProject.rc2 文件"添加手动编辑此资源。有关资源中的字段中的每一个含义的详细内容,请参阅帮助中的 VERSIONINFO 资源语句。替换宏 FILEVER 和 PRODUCTVER 的文件和产品数据。同样,替换宏 STRFILEVER 和 STRPRODUCTVER 的文件和产品字符串数据。添加# VS_VERSION_INFO 资源语句前立即包括VersionNo.h。现在版本资源看起来://///////////////////////////////////////////////////////////////////// // // Version // #include "VersionNo.h" VS_VERSION_INFO VERSIONINFO FILEVERSION FILEVER PRODUCTVERSION PRODUCTVER FILEFLAGSMASK 0x3fL #ifdef _DEBUG FILEFLAGS 0x1L #else FILEFLAGS 0x0L #endif FILEOS 0x4L FILETYPE 0x1L FILESUBTYPE 0x0L BEGIN BLOCK "StringFileInfo" BEGIN BLOCK "040904b0" BEGIN VALUE "Comments", "Sample Application\0" VALUE "CompanyName", "Microsoft Corp.\0" VALUE "FileDescription", "MyProject MFC Application\0" VALUE "FileVersion", STRFILEVER VALUE "InternalName", "MyProject\0" VALUE "LegalCopyright", "Copyright (C) 1997\0" VALUE "OriginalFilename", "MyProject.EXE\0" VALUE "ProductName", "MyProject Application\0" VALUE "ProductVersion", STRPRODUCTVER END END BLOCK "VarFileInfo" BEGIN VALUE "Translation", 0x409, 1200 END END 创建与您的项目位于同一目录中名为 VersionNo.h 的头文件。此文件将包含以下语句,将使用在步骤 2 中的宏的定义:#define FILEVER 1,0,0,1 #define PRODUCTVER 1,0,0,1 #define STRFILEVER "1, 0, 0, 1\0" #define STRPRODUCTVER "1, 0, 0, 1\0" 注意: 添加换行符和回车换行符的最后一行。现在,MyProject.rc 文件包含 MyProject.rc2,并且 MyProject.rc2 文件包含 VersionNo.h。将使用 Visual Basic 脚本宏修改 VersionNo.h 文件的内容。宏描述控点的下方 Visual c + + BuildFinish 事件,因此它将不激发直到生成完成。每当调用此 VB 脚本代码时,它首先按固定金额、 增加内部的头文件的版本号,然后保存该文件,并将其关闭。在后续的生成过程中可执行文件中包含新的版本号。要安装并使用 VB 脚本代码,请执行以下 *** 作:打开现有的 DSM (宏观) 文件,或在 Visual c + + 中创建一个新的 DSM 文件。要创建一个新文件,请单击文件菜单上的新建、文件选项卡上选择的宏文件、 为其指定一个名称,和单击确定粘贴下面的以下 VB 脚本代码 (在 Visual c + + 中,无法安装空 DSM 文件 ; 下一步解释安装):Function GetProjectDir(FullName) 'VC++ doesn't provide any method for getting the path of the active project 'See the VB Script reference for more information on the VB Script functions 'used in this function Dim proj_path proj_path = Split(StrReverse(FullName),"\",-1,1) Dim count count = UBound(proj_path) Dim full_path full_path = "" Dim i for i = 1 to count full_path = full_path &"\" &proj_path(i) next GetProjectDir = StrReverse(full_path) End Function Sub ReplaceText(selection, count, incrementby) 'selection represents the TextSelection object 'count represents the position of the version number to be incremented 'incrementby represents a number that will be added to the existing version number selection.WordRight dsMove, count selection.WordRight dsExtend, 1 Dim str str = selection.Text str = str + incrementby selection.Text = str End Sub Sub Application_BuildFinish(numError, numWarning) 'This event will be triggered after every build of a project 'You can check numError and/or numWarning to determine if you want to continue 'If numError 0 Then 'exit sub 'Obtain the full path of the active project Dim full_path full_path = GetProjectDir(ActiveProject.FullName) full_path = full_path &"versionno.h" 'Open the VersionNo.h file Documents.Open full_path 'Obtain the TextSelection object Dim selection set selection = ActiveDocument.Selection selection.StartOfDocument 'Increment the version information ReplaceText selection, 9, 1 selection.LineDown selection.StartOfLine ReplaceText selection, 9, 1 selection.LineDown selection.StartOfLine ReplaceText selection, 10, 1 selection.LineDown selection.StartOfLine ReplaceText selection, 10, 1 ActiveDocument.Save ActiveDocument.Close End Sub 注:此代码是不受支持的示例。为您生成的方案,您可以修改它。如果未安装,请安装 DSM 文件。要安装,请在工具菜单上单击自定义、 单击加载项和宏文件选项卡、 浏览以选择 DSM 文件中,并单击关闭从生成菜单中选择生成MyProject.exe。生成完成后,打开 VersionNo.h 文件。它将包含以下语句:#define FILEVER 1,0,0,2 #define PRODUCTVER 1,0,0,2 #define STRFILEVER "1, 0, 0, 2\0" #define STRPRODUCTVER "1, 0, 0, 2\0" 如果您生成代码再次中的此版本信息包含在可执行文件和版本信息就会增加。


欢迎分享,转载请注明来源:内存溢出

原文地址: http://www.outofmemory.cn/bake/11873942.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-05-19
下一篇 2023-05-19

发表评论

登录后才能评论

评论列表(0条)

保存