-
January 26th, 2009, 07:16 AM
#1
how can i get author, comments, ... from a file ?
Hello everybody,
i want to get some informations of a file, but i did not know how i could recieve this ?!
fortunately i found how i could read the file version, what is shown at the end of this post.
but i am also interested in the other informations like
- author
- comments
- copyright
- and so on ...
currently i am not able to get these thing ....
Does anybody know how i can get these informations !?
this would be a huge help ... !
best regards ...
#50
// ** part of my source code
// ** using visual c++ 6.0
// ** in this code i have an output which 'works fine', this shows the correct version number.
// ** the 'useless output' shows some information, which i couldn't handle ?!
// ** the 'translation' of CString strCurrFileName seems to be unusual, but i did not know an other way how i could parse from CString to LPTSTR.
LPCSTR lpszFilePathC = strCurrFileName;
LPTSTR lpszFilePath = (LPTSTR)lpszFilePathC;
DWORD dwDummy;
DWORD dwFVISize = GetFileVersionInfoSize( lpszFilePath , &dwDummy );
LPBYTE lpVersionInfo = new BYTE[dwFVISize];
GetFileVersionInfo( lpszFilePath , 0 , dwFVISize , lpVersionInfo );
UINT uLen;
VS_FIXEDFILEINFO *lpFfi;
VerQueryValue( lpVersionInfo , _T("\\") , (LPVOID *)&lpFfi , &uLen );
/* // ** the struct entries
_VS_FIXEDFILEINFO { // vsffi
DWORD dwSignature;
DWORD dwStrucVersion;
DWORD dwFileVersionMS;
DWORD dwFileVersionLS;
DWORD dwProductVersionMS;
DWORD dwProductVersionLS;
DWORD dwFileFlagsMask;
DWORD dwFileFlags;
DWORD dwFileOS;
DWORD dwFileType;
DWORD dwFileSubtype;
DWORD dwFileDateMS;
DWORD dwFileDateLS;
} VS_FIXEDFILEINFO;
*/
/* this works fine: */
DWORD dwFileVersionMS = lpFfi->dwFileVersionMS;
DWORD dwFileVersionLS = lpFfi->dwFileVersionLS;
/* experiments : */
DWORD asig = lpFfi->dwSignature;
DWORD asver = lpFfi->dwStrucVersion;
DWORD apms = lpFfi->dwProductVersionMS;
DWORD apls = lpFfi->dwProductVersionLS;
DWORD atyp = lpFfi->dwFileType;
/* no memory leaks */
delete [] lpVersionInfo;
/* this works fine: */
DWORD dwLeftMost = HIWORD(dwFileVersionMS);
DWORD dwSecondLeft = LOWORD(dwFileVersionMS);
DWORD dwSecondRight = HIWORD(dwFileVersionLS);
DWORD dwRightMost = LOWORD(dwFileVersionLS);
/* experiments : */
DWORD bsig = HIWORD(asig);
DWORD csig = LOWORD(asig);
CString aasig = (CString) asig,
bbsig = (CString) bsig,
cbsig = (CString) csig;
CString WorksFine; WorksFine.Format("Version: %d.%d.%d.%d\n" , dwLeftMost, dwSecondLeft,dwSecondRight, dwRightMost );
CString UselessOutput; UselessOutput.Format("Signature = %x "
"\nStructVersion = %x \n ProductVersionMS = %x, \nProductVersionLS = %x \n FileType = %x"
"HISig = %d, LOSig = %d",
asig, asver, apms, apls, atyp, bsig, csig);
AfxMessageBox(WorksFine);
AfxMessageBox(UselessOutput);
Last edited by Raute50; January 26th, 2009 at 11:20 AM.
-
January 26th, 2009, 07:46 AM
#2
Re: how can i get author, comments, ... from a file ?
You should call VerQueryValue for all the fields you need (such as "LegalCopyright", "Comments", and so on). See the example in MSDN article "VerQueryValue".
You also could use some free thirdparty class to obtain the Version info. (Get VersionInfo from resource file)
Victor Nijegorodov
-
January 26th, 2009, 08:26 AM
#3
Re: how can i get author, comments, ... from a file ?
i tried to adapt the information from the VeryQueryValue Page and your post, but unfortunately i did not get the 'comments' Information
i used the following lines:
/* when i looked with my debugger on the lpFfi-entries, there is nothing usefull inside */
VerQueryValue( lpVersionInfo, TEXT("Comments"), (LPVOID*) &lpFfi, &uLen);
/* at the opposite: with the following line i got some information ... specially the 'version' information, after some more work i shown i the first post */
VerQueryValue( lpVersionInfo , _T("\\") , (LPVOID *)&lpFfi , &uLen );
what is the fault in my proceeding ?
-
January 26th, 2009, 08:45 AM
#4
Re: how can i get author, comments, ... from a file ?
Maybe "Comments" is not available in the file you are looking at. You have to check the return value of VerQueryValue() along with the size of the buffer returned (parameter 4). Check MSDN documentation for details.
And just looking through your code quickly, I notice invalid casting of DWORD to CString:
DWORD bsig = HIWORD(asig);
CString bbsig = (CString) bsig,
-
January 26th, 2009, 09:07 AM
#5
Re: how can i get author, comments, ... from a file ?
Originally Posted by 0xC0000005
Maybe "Comments" is not available in the file you are looking at. You have to check the return value of VerQueryValue() along with the size of the buffer returned (parameter 4). Check MSDN documentation for details.
And just looking through your code quickly, I notice invalid casting of DWORD to CString:
DWORD bsig = HIWORD(asig);
CString bbsig = (CString) bsig,
in my self made examples the files should have already some "Comments" ...
perhaps the comments i mean are not the comments VerQueryValue does mean ?!
for completenes (and perhaps for finding an error):
'my comments' appear after choosing the 'Version' tab of the 'Properties' option of the file as a part of 'Other version information' ...
after my try to look for the "Description" the result was the same: nothing
perhaps i was writing a little bit to unclean or in fact of the quickly looking ...
the casts where only an experiment of trying ... that is why the comment are at the places
/* experiments : */
i changed my code to the following and with my above tries there was always the first message box shown ... and never the second ...
if ( 0 == VerQueryValue( lpVersionInfo, TEXT("Description"), (LPVOID*) &lpFfi, &uLen) )
AfxMessageBox("first VerQueryValue returned 0");
if ( 0 == VerQueryValue( lpVersionInfo , _T("\\") , (LPVOID *)&lpFfi , &uLen ) )
AfxMessageBox("second VerQueryValue returned 0");
-
January 26th, 2009, 10:32 AM
#6
Re: how can i get author, comments, ... from a file ?
Getting version info strings is complicated by the fact that the structure holds fields for multiple languages and code pages. Here is some simple working code that retrieves the "Comments" section for each language:
Code:
void PrintVersionInfoComments(LPTSTR lpszFilePath)
{
// Get version info
DWORD dwDummy = 0xffffffff;
const DWORD dwFVISize = GetFileVersionInfoSize( lpszFilePath , &dwDummy );
ASSERT(0!=dwFVISize);
LPBYTE pBlock = new BYTE[dwFVISize];
GetFileVersionInfo( lpszFilePath, 0, dwFVISize, pBlock );
// Structure used to store enumerated languages and code pages.
struct LANGANDCODEPAGE
{
WORD wLanguage;
WORD wCodePage;
} *lpTranslate;
// How many languages in the version info?
lpTranslate = 0;
UINT cbTranslate = 0;
VerQueryValue(pBlock, _T("\\VarFileInfo\\Translation"), (LPVOID*)&lpTranslate, &cbTranslate);
const int nLanguages = cbTranslate / sizeof(LANGANDCODEPAGE);
// For each language...
for( int i=0; i<nLanguages; ++i )
{
TCHAR subBlock[256];
// Create subBlock for current language and code page
_stprintf( subBlock,
_T("\\StringFileInfo\\%04x%04x\\Comments"),
lpTranslate[i].wLanguage,
lpTranslate[i].wCodePage
);
LPBYTE pBytes = 0;
UINT nBytes = 0;
VerQueryValue(pBlock, subBlock, (LPVOID *)&pBytes, &nBytes);
if(0==nBytes)
{
TRACE1("\"%s\" does not exist in this file\n", subBlock);
}
else
{
TRACE2("\"%s\" = \"%s\"\n", subBlock, (LPCTSTR)pBytes);
}
}
}
This code is very basic, does virtually no error checking, and uses MFC TRACE MACROS for display. But it does work. Modify as necessary.
-
January 26th, 2009, 11:18 AM
#7
Re: how can i get author, comments, ... from a file ?
thanks a lot ...
i have seen some pieces of your example during my search ... but quit yet these things are put together ...
it is working well and currently it is exactly what i need ...
unfortunately i do not understand everything ... and i am wondering about some details ...
but i am very happy to have such a solution ....
all the best ....
#50
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|