#include <stdio.h>
//--------------------------------
String GetFileVersionInfo(char *ModulePath, String KeyName)
{
LPVOID lpStr1 = NULL, lpStr2 = NULL;
WORD* wTmp;
DWORD dwHandlev = NULL;
UINT dwLength;
char sFileName[1024] = {0};
char sTmp[1024] = {0};
String sInfo;
LPVOID* pVersionInfo;
if(ModulePath == NULL) GetModuleFileName(NULL, sFileName, 1024);
else strcpy(sFileName, ModulePath);
DWORD dwInfoSize = GetFileVersionInfoSize((char*)(LPCTSTR)sFileName, &dwHandlev);
if(dwInfoSize)
{
pVersionInfo = new LPVOID[dwInfoSize];
if(GetFileVersionInfo((char*)(LPCTSTR)sFileName, dwHandlev, dwInfoSize, pVersionInfo))
{
if(VerQueryValue(pVersionInfo, "\\VarFileInfo\\Translation", &lpStr1, &dwLength))
{
wTmp = (WORD*)lpStr1;
sprintf(sTmp, ("\\StringFileInfo\\%04x%04x\\" + KeyName).c_str(), *wTmp, *(wTmp + 1));
if(VerQueryValue(pVersionInfo, sTmp, &lpStr2, &dwLength)) sInfo = (LPSTR)lpStr2;
}
}
delete[] pVersionInfo;
}
return sInfo;
}
//--------------------------------
void __fastcall TForm1::Button1Click(TObject *Sender)
{
Label2->Caption = "Wersja pliku: " + GetFileVersionInfo(NULL, "FileVersion"); // pobranie wersji programu z którego funkcja jest uruchamiana
}
//--------------------------------
Tak jak pisałem wcześniej liczyłem na to, że jest prosta, gotowa funkcja do tego typu operacji.
[BCC32 Error] GetVersion.h(26): E2034 Cannot convert 'wchar_t *' to 'const char *'
[BCC32 Error] GetVersion.h(26): E2342 Type mismatch in parameter '__format' (wanted 'const char *', got 'wchar_t *')
("\\StringFileInfo\\%04x%04x\\" + KeyName)
//---------------------------------------------------------------------------
UnicodeString myGetFileVersionInfo(char *ModulePath, UnicodeString KeyName)
{
LPVOID lpStr1 = NULL, lpStr2 = NULL;
WORD* wTmp;
DWORD dwHandlev = NULL;
UINT dwLength;
char sFileName[1024] = {0};
char sTmp[1024] = {0};
UnicodeString sInfo;
LPVOID* pVersionInfo;
if(ModulePath == NULL) GetModuleFileName(NULL, sFileName, 1024);
else strcpy(sFileName, ModulePath);
DWORD dwInfoSize = GetFileVersionInfoSize((char*)(LPSTR)sFileName, &dwHandlev);
if(dwInfoSize)
{
pVersionInfo = new LPVOID[dwInfoSize];
if(GetFileVersionInfo((char*)(LPCTSTR)sFileName, dwHandlev, dwInfoSize, pVersionInfo))
{
if(VerQueryValue(pVersionInfo, "\\VarFileInfo\\Translation", &lpStr1, &dwLength))
{
wTmp = (WORD*)lpStr1;
sprintf(sTmp, ("\\StringFileInfo\\%04x%04x\\" + KeyName).t_str(), *wTmp, *(wTmp + 1));
if(VerQueryValue(pVersionInfo, sTmp, &lpStr2, &dwLength)) sInfo = (LPCTSTR)lpStr2;
}
}
delete[] pVersionInfo;
}
return sInfo;
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Button1Click(TObject *Sender)
{
Label1->Caption = "Wersja pliku: " + myGetFileVersionInfo(NULL, "FileVersion");
}
//---------------------------------------------------------------------------
Powrót do Ogólne problemy z programowaniem
Użytkownicy przeglądający ten dział: Brak zalogowanych użytkowników i 13 gości