C++-如何用c++实现修改一个exe文件版本信息中的备注字段
//在Delphi中获得exe备注字段的方法如下,那么如何设置该字段呢?
function TMe.getFileComments(): string;
var
VerInfoSize: DWORD;
VerInfo: Pointer;
VerValueSize: DWORD;
Dummy: DWORD;
VerValue: PVSFixedFileInfo;
TransLationStr:String;
begin
VerInfoSize := GetFileVersionInfoSize(PChar(Application.ExeName),Dummy);
GetMem(VerInfo, VerInfoSize);
GetFileVersionInfo(PChar(Application.ExeName), 0, VerInfoSize, VerInfo);
VerQueryValue(VerInfo, 'VarFileInfoTranslation', Pointer(VerValue), VerValueSize);
TransLationStr:=IntToHex(MakeLong(HiWord(Longint(Pointer(VerValue)^)),LoWord(Longint(Pointer(VerValue)^))),8);
VerQueryValue(VerInfo,Pchar('StringFileInfo'+TransLationStr+'Comments'),Pointer(VerValue),Cardinal(VerValueSize));
Result := pChar(VerValue);
FreeMem(VerInfo);
end;
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
dephi不熟悉,我这里有VC++版本的
HRSRC hResLoad; // handle to loaded resource
HANDLE hExe; // handle to existing .EXE file
HRSRC hRes; // handle/ptr. to res. info. in hExe
HANDLE hUpdateRes; // update resource handle
char *lpResLock; // pointer to resource data
BOOL result;
// Load the .EXE file that contains the dialog box you want to copy.
hExe = LoadLibrary("yourapp.exe");
if (hExe == NULL)
{
ErrorHandler("Could not load exe.");
}
// Locate the dialog box resource in the .EXE file.
hRes = FindResource(hExe, "AboutBox", RT_DIALOG);
if (hRes == NULL)
{
ErrorHandler("Could not locate dialog box.");
}
// Load the dialog box into global memory.
hResLoad = LoadResource(hExe, hRes);
if (hResLoad == NULL)
{
ErrorHandler("Could not load dialog box.");
}
// Lock the dialog box into global memory.
lpResLock = LockResource(hResLoad);
if (lpResLock == NULL)
{
ErrorHandler("Could not lock dialog box.");
}
// Open the file to which you want to add the dialog box resource.
hUpdateRes = BeginUpdateResource("yourapp.exe", FALSE);
if (hUpdateRes == NULL)
{
ErrorHandler("Could not open file for writing.");
}
// Add the dialog box resource to the update list.
result = UpdateResource(hUpdateRes, // update resource handle
RT_DIALOG, // change dialog box resource
"AboutBox", // dialog box name
MAKELANGID(LANG_NEUTRAL, SUBLANG_NEUTRAL), // neutral language
lpResLock, // ptr to resource info
SizeofResource(hExe, hRes)); // size of resource info.
if (result == FALSE)
{
ErrorHandler("Could not add resource.");
}
// Write changes to FOOT.EXE and then close it.
if (!EndUpdateResource(hUpdateRes, FALSE))
{
ErrorHandler("Could not write changes to file.");
}
// Clean up.
if (!FreeLibrary(hExe))
{
ErrorHandler("Could not free executable.");
}