c++ GetFileVersionInfo

Hey Super,

Vielen Dank euch allen :)
Die Methode funktioniert jetzt einwandfrei.

Hier ist die MFC unabhängige und getestet Version von GetFileVersionInfoString()

Grüsse aus der kalten Schweiz :)

Edit: Fehler im Code korrigiert.

Code:
/********************************************************************************************
*	This Methode returns the Version Number of a file
*	It needs a fileName and a value for the reference.
*	Example:
*	GetFileVersionInfoString("myprogramm.dll","FileVersion")
*	-> It returns a CString 1.0.1 
*	If there is no FileVersion available: it returns "no data".
*	You may use also use for strProperty: CompanyName, LegalCopyright, LegalTrademarks usw...
*/
const std::string GetFileVersionInfoString(std::string strFile, std::string strProperty)
{
    int rc;
    UINT nLen;
    DWORD dwHandle = 0;
	std::string strBuffer;
    char* strValue=0;
	std::string returnValue;
	std::string strBlock;
    void *lpPropertyBuffer;

	struct LANGANDCODEPAGE
		{
		  WORD wLanguage;
		  WORD wCodePage;
		} *lpTranslate;

	DWORD temp(0);
	const DWORD size(::GetFileVersionInfoSize(strFile.c_str(), &temp));
	unsigned char* ptr_buffer(new unsigned char[size]);
	if(::GetFileVersionInfo(strFile.c_str(), 0, size, reinterpret_cast<LPVOID>(ptr_buffer)))
	{
		if(::VerQueryValueW(ptr_buffer,L"\\VarFileInfo\\Translation",(LPVOID *) &lpTranslate,&nLen))
		{
			strBlock=Format("\\StringFileInfo\\%04x%04x\\%s",
				lpTranslate->wLanguage,
				lpTranslate->wCodePage,
				strProperty.c_str());
		}
		rc=VerQueryValue(ptr_buffer,strBlock.c_str(), &lpPropertyBuffer,&nLen);
		if (rc!=0 && nLen > 0)
		{
			strValue=new char[nLen+1];
			strncpy(strValue,(char *) lpPropertyBuffer,nLen);
		}
		returnValue=strValue;
		delete[] strValue;
	}
	else returnValue="no data";
    return returnValue;
}
 
Zuletzt bearbeitet:
Zurück