001
11.09.2003, 18:21 Uhr
Uwe
C/C++ Master (Administrator)
|
Hallo, irgendwann mal im Netz gefunden:
C++: |
//----------------------------------------------------------------- // Klasse zum Auslesen der Versionsinformationen aus den Windows-Exe und DLLs //----------------------------------------------------------------- // Verwendung: // Füllen einer Memo-Komponente mit Vesions-Informationen des // Windows-Notepads: VerInfo * pVer = new VerInfo("C:\\WINDOWS\\NOTEPAD.EXE"); for(int ilCount = 0; ilCount < 10; ilCount++) { Memo1 -> Lines -> Add(pVer -> GetVerInfo(ilCount)); } if(pVer != NULL) { delete pVer; pVer = NULL; } // Anstatt ilCount kann der Funktion GetVerInfo()-Funktion eine der unten // aufgelisteten Konstanten übergeben werden //-----------------------------------------------------------------
--- xyz.h ---
//---------------------------------------------------------------- // Konstanten für die Verwendung als Parameter mit der // Funktion GetVerInfo(int ilId): //----------------------------------------------------------------- const int VI_COMPANY_NAME = 0; // Firmen-Name const int VI_FILE_DESCRIPTION = 1; // Dateibeschreibung const int VI_FILE_VERSION = 2; // Versionsnummer const int VI_INTERNAL_NAME = 3; // Interner Name const int VI_LEGAL_COPYRIGHT = 4; // Copyright-Info const int VI_LEGAL_TRADEMARKS = 5; // Warenzeichen const int VI_ORIGINAL_FILENAME = 6; // Orig.-Dateiname const int VI_PRODUCT_NAME = 7; // Produktname const int VI_PRODUCT_VERSION = 8; // Produkt-Version const int VI_FILE_COMMENTS = 9; // Kommentare
//--------------------------------------------------------------------- // Klassendeklaration //-------------------------------------------------------------------
class VerInfo { private: AnsiString company_name; AnsiString file_description; AnsiString file_version; AnsiString internal_name; AnsiString legal_copyright; AnsiString legal_trademarks; AnsiString original_filename; AnsiString product_name; AnsiString product_version; AnsiString file_comments;
protected: char *GetVersionKey(char *buffer, const AnsiString &prefix, char *key);
public: // Konstuktor (als Parameter wird der Dateiname übergeben) VerInfo(AnsiString slExeName); // Funktion gibt die angeforderte Ver-Info zurück: AnsiString GetVerInfo(int ilId); };
--- xyz.cpp ---
//------------------------------------------------------------------- // Konstruktor der VerInfo - Klasse //------------------------------------------------------------------- VerInfo::VerInfo(AnsiString slExeName) { DWORD handle; // Dummy, Windows does not use this parameter. DWORD size; if(!FileExists(slExeName)) { slExeName = Application -> ExeName; }
size = GetFileVersionInfoSize(slExeName.c_str(), &handle);
if(size == 0) return; // No file information
char *buffer = new char [size]; bool status = GetFileVersionInfo(slExeName.c_str(), 0, size, buffer); if(!status) { delete [] buffer; return; }
// Extract the language ID UINT datasize; unsigned short *translation;
/*status =*/ VerQueryValue( buffer, "\\VarFileInfo\\Translation", (void **) &translation, &datasize);
// Here we create a prefix string that is the same for all the keys. AnsiString prefix = "\\StringFileInfo\\" + AnsiString::IntToHex(translation [0], 4) + AnsiString::IntToHex(translation [1], 4);
// Extract all the version information. company_name = GetVersionKey(buffer, prefix, "CompanyName"); file_description = GetVersionKey(buffer, prefix, "FileDescription"); file_version = GetVersionKey(buffer, prefix, "FileVersion"); internal_name = GetVersionKey(buffer, prefix, "InternalName"); legal_copyright = GetVersionKey(buffer, prefix, "LegalCopyright"); legal_trademarks = GetVersionKey(buffer, prefix, "LegalTrademarks"); original_filename = GetVersionKey(buffer, prefix, "OriginalFilename"); product_name = GetVersionKey(buffer, prefix, "ProductName"); product_version = GetVersionKey(buffer, prefix, "ProductVersion"); file_comments = GetVersionKey(buffer, prefix, "Comments"); delete [] buffer; }
//-------------------------------------------------------------------- // Extrahiert Versions-Info aus dem buffer //------------------------------------------------------------------- char* VerInfo::GetVersionKey(char *buffer, const AnsiString &prefix, char *key) { char *data; UINT datasize; AnsiString fullkey = prefix + "\\" + key; bool status = VerQueryValue(buffer, fullkey.c_str(), (void **) &data, &datasize); if(status) return(data); else return(""); }
//------------------------------------------------------------------- // Gibt die Vesions-Infos zurück //------------------------------------------------------------------- AnsiString VerInfo::GetVerInfo(int ilId) { switch (ilId) { case VI_COMPANY_NAME : return company_name; case VI_FILE_DESCRIPTION : return file_description; case VI_FILE_VERSION : return file_version; case VI_INTERNAL_NAME : return internal_name; case VI_LEGAL_COPYRIGHT : return legal_copyright; case VI_LEGAL_TRADEMARKS : return legal_trademarks; case VI_ORIGINAL_FILENAME : return original_filename; case VI_PRODUCT_NAME : return product_name; case VI_PRODUCT_VERSION : return product_version; case VI_FILE_COMMENTS : return file_comments; default : return file_version; } }
|
--edit-- VCL.h noch includieren -- "Es ist schwierig, ein Programm wirklich idiotensicher zu machen, weil Idioten so genial sind."
Bis dann... Uwe Dieser Post wurde am 11.09.2003 um 18:22 Uhr von Uwe editiert. |