線上訂房服務-台灣趴趴狗聯合訂房中心
發文 回覆 瀏覽次數:5945
推到 Plurk!
推到 Facebook!

使用GetFileVersionInfo( ),VerQueryValue( )等函数的问题

答題得分者是:RaynorPao
bigdogchina
版主


發表:238
回覆:523
積分:312
註冊:2003-04-28

發送簡訊給我
#1 引用回覆 回覆 發表時間:2003-07-24 18:07:41 IP:211.162.xxx.xxx 未訂閱
大大们好,小弟我:问题多多,错综复杂,束手无策,盼您点拨 我想读出程式的版本信息,翻遍> > 同时也查询了站内的相关内容: class="code"> void __fastcall TForm1::Button1Click(TObject *Sender) { union { int Int; char ch[4]; }i_c; DWORD dwHandle,dwSize,dwLangueID; char *Block,*Tran; char Buf[256]; UINT Len; AnsiString Item; AnsiString sPath = "C:\\Winnt\\Explorer.exe"; dwSize = GetFileVersionInfoSize(sPath.c_str(),&dwHandle); if(dwSize == 0) return; //无版本信息 dwSize ; Block = new char[dwSize]; GetFileVersionInfo(sPath.c_str(),dwHandle,dwSize,(void *)Block); VerQueryValue(Block,"\\VarFileInfo\\Translation",(void **)&Tran,&Len); i_c.ch[0] = Tran[0]; i_c.ch[1] = Tran[1]; i_c.ch[2] = Tran[2]; i_c.ch[3] = Tran[3]; dwLangueID = i_c.Int; //得到语言版本号 Item = "\\StringFileInfo\\"; Item = Item IntToStr(dwLangueID) "\\ProductName"; if(VerQueryValue(Block,Item.c_str(),(void **)&Buf,&Len)) { ShowMessage(Buf); //显示程式名称 } } 我高高兴兴的按下Run,等着秀出程式名Explorer.exe,可是,现实和希望总是相反的,什么都没有,连个
------
人生在勤,不索何获?
collonil
中階會員


發表:13
回覆:56
積分:63
註冊:2003-03-26

發送簡訊給我
#2 引用回覆 回覆 發表時間:2003-07-24 19:00:35 IP:210.71.xxx.xxx 未訂閱
BCB6(之前版本不知有沒有)中有一個VersionInfo Component的sample, 如果您不介意的話可以裝起來使用, 非常方便...    -- BCB學習中~~
bigdogchina
版主


發表:238
回覆:523
積分:312
註冊:2003-04-28

發送簡訊給我
#3 引用回覆 回覆 發表時間:2003-07-24 19:50:27 IP:211.162.xxx.xxx 未訂閱
collonil大哥,感谢您的提示,谢谢!!! 可是我用的是BCB5 + Win2000 + SP3,我照您说的去找了,发现没有,如果我不装BCB6就不能解决问题了啊,好伤心啊, > 人生在勤,不索何获?
------
人生在勤,不索何获?
collonil
中階會員


發表:13
回覆:56
積分:63
註冊:2003-03-26

發送簡訊給我
#4 引用回覆 回覆 發表時間:2003-07-24 20:27:52 IP:210.71.xxx.xxx 未訂閱
其實我有用API寫過, 但是程式不在手邊... 明晚才會用到那台電腦, 萬一到明晚您的問題都還沒解決的話, 我再把我的code貼出來讓您參考..    -- BCB學習中~~
RaynorPao
版主


發表:139
回覆:3622
積分:7025
註冊:2002-08-12

發送簡訊給我
#5 引用回覆 回覆 發表時間:2003-07-24 22:52:47 IP:61.221.xxx.xxx 未訂閱
bigdogchina 你好: 試試看這樣寫可不可以達到目的呢?? < class="code"> DWORD dwVerInfoSize=0; dwVerInfoSize=GetFileVersionInfoSize("C:\\Winnt\\explorer.exe", &dwVerInfoSize); BYTE *bVerInfoBuf=new BYTE[dwVerInfoSize]; if(GetFileVersionInfo("C:\\Winnt\\explorer.exe", 0, dwVerInfoSize, bVerInfoBuf)) { VS_FIXEDFILEINFO *vsInfo; UINT vsInfoSize; if(VerQueryValue(bVerInfoBuf, "\\", (void**)&vsInfo, &vsInfoSize)) { int iFileVerMajor=HIWORD(vsInfo->dwFileVersionMS); int iFileVerMinor=LOWORD(vsInfo->dwFileVersionMS); int iFileVerRelease=HIWORD(vsInfo->dwFileVersionLS); int iFileVerBuild=LOWORD(vsInfo->dwFileVersionLS); ShowMessage(IntToStr(iFileVerMajor) "." IntToStr(iFileVerMinor) "." IntToStr(iFileVerRelease) "." IntToStr(iFileVerBuild)); } } delete bVerInfoBuf; -- Enjoy Researching & Developing --
------
-- 若您已經得到滿意的答覆,請適時結案!! --
-- 欲知前世因,今生受者是;欲知來世果,今生做者是 --
-- 一切有為法,如夢幻泡影,如露亦如電,應作如是觀 --
bigdogchina
版主


發表:238
回覆:523
積分:312
註冊:2003-04-28

發送簡訊給我
#6 引用回覆 回覆 發表時間:2003-07-25 12:40:37 IP:211.162.xxx.xxx 未訂閱
虔诚的感谢collonil,RaynorPao两位大大,您们辛苦了!!! collonil大哥,我有个不情之请,您能否把code贴出来,我很想拜读您的大做,希望您满足我这个愿望,好吗? >,不过小弟我反应迟钝,仍然有个问题未解:直接用> > 我想将 <> "> 都秀出来.劳您费心了. 我今天一上午都在仔细琢磨到底我的代码问题出在那?后来在> > 注意哦,语言版本是 class="code"> int __fastcall TForm1::MyIntToHex(int Int,char Hex[],bool Add0x) { struct hex_struct { unsigned eight : 4; unsigned seven : 4; unsigned six : 4; unsigned five : 4; unsigned four : 4; unsigned three : 4; unsigned two : 4; unsigned one : 4; }; union { unsigned Int; hex_struct Hex; }ih; ih.Int = (unsigned)Int; int i = 0; if(Add0x) { Hex[i ]='0'; Hex[i ]='x'; } Hex[i ]=Num_Char(ih.Hex.one); Hex[i ]=Num_Char(ih.Hex.two); Hex[i ]=Num_Char(ih.Hex.three); Hex[i ]=Num_Char(ih.Hex.four); Hex[i ]=Num_Char(ih.Hex.five); Hex[i ]=Num_Char(ih.Hex.six); Hex[i ]=Num_Char(ih.Hex.seven); Hex[i ]=Num_Char(ih.Hex.eight); Hex[i]='\0'; return i; } char __fastcall TForm1::Num_Char(unsigned numeric) { const Asc0=48; const AscA=65-10; if(numeric<=9)return char(Asc0 numeric); if((numeric>=10)&&(numeric<=15))return char(AscA numeric); return ' '; } void __fastcall TForm1::Button1Click(TObject *Sender) { union { int Int; char ch[4]; }i_c; DWORD dwHandle,dwSize,dwBytes,dwLangueID; char *Block,*Tran; char Buf[256]; char Hex[14]; UINT Len; AnsiString Item; AnsiString sPath = "C:\\Program Files\\Internet Explorer\\IEXPLORE.EXE"; dwSize = GetFileVersionInfoSize(sPath.c_str(),&dwHandle); if(dwSize == 0) return; //无版本信息 dwSize ; Block = new char[dwSize]; GetFileVersionInfo(sPath.c_str(),dwHandle,dwSize,(void *)Block); VerQueryValue(Block,"\\VarFileInfo\\Translation",(void **)&Tran,&Len); i_c.ch[0] = Tran[0]; i_c.ch[1] = Tran[1]; i_c.ch[2] = Tran[2]; i_c.ch[3] = Tran[3]; dwLangueID = i_c.Int; Item = "\\StringFileInfo\\"; MyIntToHex(dwLangueID,Hex,false); //将其语言版本转换为16进制 Item = Item Hex "\\FileDescription"; if(VerQueryValue(Block,Item.c_str(),(void **)&Buf,&Len)) { ShowMessage(Buf); } } 结果还是一样,执行VerQueryValue()时,仍然返回false.天啊,VerQueryValue()要求的每个参数,我都按它的要求去做了,为什么还是返回false啊,看来实在不行,也只有放弃了 發表人 -
------
人生在勤,不索何获?
axsoft
版主


發表:681
回覆:1056
積分:969
註冊:2002-03-13

發送簡訊給我
#7 引用回覆 回覆 發表時間:2003-07-25 13:43:48 IP:61.218.xxx.xxx 未訂閱
bigdogchina您好:  參考這個元件試試   TWSAExeVersion  下載: http://delphi.ktop.com.tw/loadfile.php?TOPICID=10836073&CC=242347    檔案來源已經不可考了!    TWSAExeVersion ==============    This component allows the developer to extract version information about a Borland C++ Builder application at run time. It can be placed on a form and version information can be accessed through the following properties:    CompanyName      FileDescription  FileVersion      InternalName     LegalCopyright   LegalTrademarks  OriginalFilename ProductName      ProductVersion   Comments         MajorVersion     MinorVersion     Release          Build               Component Files: WSAExeVersion.cpp WSAExeVersion.h WSAExeVersion.res    Package Files: WSASystem.bpk WSASystem.cpp WSASystem.res    Example Files: AboutDlg.cpp AboutDlg.dfm AboutDlg.h     Author contact information: Peter Tersteeg. Westinghouse Signals Australia. ptersteeg@westsig.com.au Comments: I wrote this component because I found there was a lot of people requesting code to retrieve version information. If you find this component useful, find/fix any bugs or enhance it in any way, please let me know. Otherwise feel free to use it in any way. HAVE A NICE DAY FOR YOU
RaynorPao
版主


發表:139
回覆:3622
積分:7025
註冊:2002-08-12

發送簡訊給我
#8 引用回覆 回覆 發表時間:2003-07-25 14:18:10 IP:203.73.xxx.xxx 未訂閱
引言: 虔诚的感谢collonil,RaynorPao两位大大,您们辛苦了!!! collonil大哥,我有个不情之请,您能否把code贴出来,我很想拜读您的大做,希望您满足我这个愿望,好吗? >,不过小弟我反应迟钝,仍然有个问题未解:直接用> > 我想将 <> "> 都秀出来.劳您费心了. 我今天一上午都在仔细琢磨到底我的代码问题出在那?后来在> > 注意哦,语言版本是 class="code"> int __fastcall TForm1::MyIntToHex(int Int,char Hex[],bool Add0x) { struct hex_struct { unsigned eight : 4; unsigned seven : 4; unsigned six : 4; unsigned five : 4; unsigned four : 4; unsigned three : 4; unsigned two : 4; unsigned one : 4; }; union { unsigned Int; hex_struct Hex; }ih; ih.Int = (unsigned)Int; int i = 0; if(Add0x) { Hex[i ]='0'; Hex[i ]='x'; } Hex[i ]=Num_Char(ih.Hex.one); Hex[i ]=Num_Char(ih.Hex.two); Hex[i ]=Num_Char(ih.Hex.three); Hex[i ]=Num_Char(ih.Hex.four); Hex[i ]=Num_Char(ih.Hex.five); Hex[i ]=Num_Char(ih.Hex.six); Hex[i ]=Num_Char(ih.Hex.seven); Hex[i ]=Num_Char(ih.Hex.eight); Hex[i]='\0'; return i; } char __fastcall TForm1::Num_Char(unsigned numeric) { const Asc0=48; const AscA=65-10; if(numeric<=9)return char(Asc0 numeric); if((numeric>=10)&&(numeric<=15))return char(AscA numeric); return ' '; } void __fastcall TForm1::Button1Click(TObject *Sender) { union { int Int; char ch[4]; }i_c; DWORD dwHandle,dwSize,dwBytes,dwLangueID; char *Block,*Tran; char Buf[256]; char Hex[14]; UINT Len; AnsiString Item; AnsiString sPath = "C:\\Program Files\\Internet Explorer\\IEXPLORE.EXE"; dwSize = GetFileVersionInfoSize(sPath.c_str(),&dwHandle); if(dwSize == 0) return; //无版本信息 dwSize ; Block = new char[dwSize]; GetFileVersionInfo(sPath.c_str(),dwHandle,dwSize,(void *)Block); VerQueryValue(Block,"\\VarFileInfo\\Translation",(void **)&Tran,&Len); i_c.ch[0] = Tran[0]; i_c.ch[1] = Tran[1]; i_c.ch[2] = Tran[2]; i_c.ch[3] = Tran[3]; dwLangueID = i_c.Int; Item = "\\StringFileInfo\\"; MyIntToHex(dwLangueID,Hex,false); //将其语言版本转换为16进制 Item = Item Hex "\\FileDescription"; if(VerQueryValue(Block,Item.c_str(),(void **)&Buf,&Len)) { ShowMessage(Buf); } } 结果还是一样,执行VerQueryValue()时,仍然返回false.天啊,VerQueryValue()要求的每个参数,我都按它的要求去做了,为什么还是返回false啊,看来实在不行,也只有放弃了 < face="Verdana, Arial, Helvetica"> bigdogchina 你好: 請問?? 你說的是不是像這個樣子呢?? < class="code"> #include "stdio.h" DWORD dwVerInfoSize=0; dwVerInfoSize=GetFileVersionInfoSize("C:\\Winnt\\explorer.exe", &dwVerInfoSize); BYTE *bVerInfoBuf=new BYTE[dwVerInfoSize]; if(GetFileVersionInfo("C:\\Winnt\\explorer.exe", 0, dwVerInfoSize, bVerInfoBuf)) { LPDWORD lang; UINT len, i, j; char buffer[MAX_PATH]; VerQueryValue(bVerInfoBuf, "\\VarFileInfo\\Translation", (void**)&lang, &len); for(i=0; iLines->Add((AnsiString)stringnames[j] ": " (AnsiString)value); } } } delete bVerInfoBuf; -- Enjoy Researching & Developing --
------
-- 若您已經得到滿意的答覆,請適時結案!! --
-- 欲知前世因,今生受者是;欲知來世果,今生做者是 --
-- 一切有為法,如夢幻泡影,如露亦如電,應作如是觀 --
bigdogchina
版主


發表:238
回覆:523
積分:312
註冊:2003-04-28

發送簡訊給我
#9 引用回覆 回覆 發表時間:2003-07-25 16:41:50 IP:211.162.xxx.xxx 未訂閱
啊,从我眼中划落的泪在脸上静静的流淌,太令人感动了.原本是山穷水尽疑无路,现在是柳岸花明又一春!!!大大您们真是安得广厦千万间,大庇天下寒士俱欢颜。 axsoft大哥,我已经将您提供的元件Install了,好用的不得了 >,我已经研读了> > 此 > 各位大大前辈对我的热诚帮助,又岂是一个谢字能表达的呢?< > 人生在勤,不索何获?
------
人生在勤,不索何获?
bigdogchina
版主


發表:238
回覆:523
積分:312
註冊:2003-04-28

發送簡訊給我
#10 引用回覆 回覆 發表時間:2003-07-25 18:46:24 IP:211.162.xxx.xxx 未訂閱
RaynorPao大大,不知您有否发现,当程式是英文版本的时候,能顺利的读出,当是中文版本的时候,就读不出来了哦.比如C:\WINNT\system32\internat.exe就读不出来 人生在勤,不索何获?
------
人生在勤,不索何获?
RaynorPao
版主


發表:139
回覆:3622
積分:7025
註冊:2002-08-12

發送簡訊給我
#11 引用回覆 回覆 發表時間:2003-07-25 20:04:52 IP:61.221.xxx.xxx 未訂閱
引言: RaynorPao大大,不知您有否发现,当程式是英文版本的时候,能顺利的读出,当是中文版本的时候,就读不出来了哦.比如C:\WINNT\system32\internat.exe就读不出来 人生在勤,不索何获? < face="Verdana, Arial, Helvetica"> bigdogchina 你好: 小弟我的讀得出來耶,以下是讀出來的結果 < class="code"> CompanyName: Microsoft Corporation FileDescription: Keyboard Language Indicator Applet FileVersion: 5.00.2920.0000 InternalName: INTERNAT LegalCopyright: Copyright (C) Microsoft Corp. 1994-1999 OriginalFilename: INTERNAT.EXE ProductName: Microsoft(R) Windows (R) 2000 Operating System ProductVersion: 5.00.2920.0000 -- Enjoy Researching & Developing --
------
-- 若您已經得到滿意的答覆,請適時結案!! --
-- 欲知前世因,今生受者是;欲知來世果,今生做者是 --
-- 一切有為法,如夢幻泡影,如露亦如電,應作如是觀 --
bigdogchina
版主


發表:238
回覆:523
積分:312
註冊:2003-04-28

發送簡訊給我
#12 引用回覆 回覆 發表時間:2003-07-26 10:18:05 IP:211.162.xxx.xxx 未訂閱
我的天,真是恨不得挖个洞钻进去,惭愧啊!!! 仔细检查了一遍> > 这也就是为什么能读英文版本而不能读中文版本的原因. > 人生在勤,不索何获?
------
人生在勤,不索何获?
系統時間:2024-04-26 4:45:04
聯絡我們 | Delphi K.Top討論版
本站聲明
1. 本論壇為無營利行為之開放平台,所有文章都是由網友自行張貼,如牽涉到法律糾紛一切與本站無關。
2. 假如網友發表之內容涉及侵權,而損及您的利益,請立即通知版主刪除。
3. 請勿批評中華民國元首及政府或批評各政黨,是藍是綠本站無權干涉,但這裡不是政治性論壇!