獲取檔案版本資訊

2021-06-08 10:53:31 字數 3640 閱讀 8091

ref : 

copy

char

*   szfilename   =   

"c:\\windows\\system32\\cmd.exe"

;   

dword

dwsize   =   getfileversioninfosize(szfilename,null);   

lpvoid

pblock   =   malloc(dwsize);   

getfileversioninfo(szfilename,0,dwsize,pblock);   

char

*   pvervalue   =   null;   

uint

nsize   =   0;   

verqueryvalue(pblock,text( "\\varfileinfo\\translation"

),   

(lpvoid

*)&pvervalue,&nsize);   

cstring   strsubblock,strtranslation,strtemp;   

strtemp.format( "000%x"

,*((unsigned   

short

int*)pvervalue));   

strtranslation   =   strtemp.right(4);   

strtemp.format( "000%x"

,*((unsigned   

short

int*)&pvervalue[2]));   

strtranslation   +=   strtemp.right(4);   

//080404b0為中文,040904e4為英文 

messagebox(strtranslation);  

//檔案描述 

strsubblock.format("\\stringfileinfo\\%s\\filedescription"

,strtranslation);   

verqueryvalue(pblock,strsubblock.getbuffersetlength(256),(lpvoid

*)&pvervalue,&nsize);   

strsubblock.releasebuffer();   

strtemp.format( "檔案描述:   %s "

,pvervalue);   

afxmessagebox(strtemp);   

//內部名稱 

strsubblock.format("\\stringfileinfo\\%s\\internalname"

,strtranslation);   

verqueryvalue(pblock,strsubblock.getbuffersetlength(256),(lpvoid

*)&pvervalue,&nsize);   

strsubblock.releasebuffer();   

strtemp.format( "內部名稱:   %s "

,pvervalue);   

afxmessagebox(strtemp);   

//合法版權 

strsubblock.format("\\stringfileinfo\\%s\\legaltrademarks"

,strtranslation);   

verqueryvalue(pblock,strsubblock.getbuffersetlength(256),(lpvoid

*)&pvervalue,&nsize);   

strsubblock.releasebuffer();   

strtemp.format( "合法版權:   %s "

,pvervalue);   

afxmessagebox(strtemp);   

//源檔名 

strsubblock.format("\\stringfileinfo\\%s\\originalfilename"

,strtranslation);   

verqueryvalue(pblock,strsubblock.getbuffersetlength(256),(lpvoid

*)&pvervalue,&nsize);   

strsubblock.releasebuffer();   

strtemp.format( "源檔名:   %s "

,pvervalue);   

afxmessagebox(strtemp);   

//產品名稱 

strsubblock.format("\\stringfileinfo\\%s\\productname"

,strtranslation);   

verqueryvalue(pblock,strsubblock.getbuffersetlength(256),(lpvoid

*)&pvervalue,&nsize);   

strsubblock.releasebuffer();   

strtemp.format("產品名稱:   %s "

,pvervalue);   

afxmessagebox(strtemp);   

//產品版本 

strsubblock.format("\\stringfileinfo\\%s\\productversion"

,strtranslation);   

verqueryvalue(pblock,strsubblock.getbuffersetlength(256),(lpvoid

*)&pvervalue,&nsize);   

strsubblock.releasebuffer();   

strtemp.format("產品版本:   %s "

,pvervalue);   

afxmessagebox(strtemp);   

//版權

,strtranslation);   

verqueryvalue(pblock,strsubblock.getbuffersetlength(256),(lpvoid

*)&pvervalue,&nsize);   

strsubblock.releasebuffer();   

strtemp.format("版權:   %s "

,pvervalue);   

afxmessagebox(strtemp);   

//公司名

strsubblock.format("\\stringfileinfo\\%s\\companyname"

,strtranslation);   

verqueryvalue(pblock,strsubblock.getbuffersetlength(256),(lpvoid

*)&pvervalue,&nsize);   

strsubblock.releasebuffer();   

strtemp.format("公司名:   %s "

,pvervalue);   

afxmessagebox(strtemp);   

free(pblock);  

EVC獲取檔案的版本資訊的方法

獲取 顯示版本資訊 開始 tchar filename t windows notes.exe 指定要獲取資訊的檔案路徑 tchar productversion 用於存放產品版本號 tchar subblock 100 用於存放要查詢的資訊名稱,相當於資料庫中要查詢的某個屬性名 unsigned ...

獲取檔案資訊

include struct stat 函式宣告 int stat const char path,struct stat buffer 注意 win32 stat linux stat 引數 path 檔案或者資料夾的路徑 buffer 獲取的資訊儲存在記憶體中 返回值 正確 返回0 錯誤 返回 ...

獲取文版版本資訊

通過api getfileversioninfosize,getfileversioninfo,verqueryvalue獲取版本資訊 首先,在mfc生成的應用程式框架中,版本資訊中有fileversion 和 productversion 兩項 productversion代表該產品的版本,fil...