Slt
Je sais qu'il est possible de l'obtenir en faisant clic droit > propriétés > version > version du fichier...
mais comment l'obtenir via code ?
merci
[REGLE] Obtenir la version d'une DLL
- Progi1984
- Messages : 2659
- Inscription : mar. 14/déc./2004 13:56
- Localisation : France > Rennes
- Contact :
[REGLE] Obtenir la version d'une DLL
Dernière modification par Progi1984 le jeu. 17/août/2006 13:20, modifié 1 fois.
Librairies & Applications : https://www.purebasic.fr/french/viewtop ... f=8&t=6220
Site Web : https://rootslabs.net
Site Web : https://rootslabs.net
-
- Messages : 1202
- Inscription : sam. 31/déc./2005 23:52
Esseye avec sa sa marchera peut etre :
GetFileInformationByHandle (HANDLE hFile, LPBY_HANDLE_FILE_INFORMATION lpFileInformation)
hFile : Handle du fichier dont les informations sont récupérées.
lpFileInformation : Pointeur vers une structure LPBY_HANDLE_FILE_INFORMATION chargée de récupérer les informations.
Code de retour : TRUE si la fonction a été exécutée avec succès, FALSE dans le cas contraire.
Voici un code que j'ai extrait d'un certain nombre de fonctions que je vais poster ces jours-ci
Il permet de retrouver la version de la Dll (enfin je n'ai fait des tests que sur certaines dll qui gère les contrôles)
A savoir que la fonction DllGetVersion n'est pas une API mais est implémentée dans chaque Dll à partir des version 4.71; dans mon code je termine l'application si on a une version inférieure à 4.71 (à adapter au besoin)
(This function is not an application programming interface (API). It is exported by name from each DLL that implements it. Currently, most of the Windows Shell and common controls DLLs implement DllGetVersion. These include, but are not limited to, Shell32.dll, Comctl32.dll, Shdocvw.dll, and Shlwapi.dll.)
La doc dit aussi :
Minimum operating systems Windows 2000, Windows NT 4.0 with Internet Explorer 4.0, Windows 98
Si tu testes sur les dll permettant d'utiliser des fonctions pour les contrôles (ListIcon, Tree, Panel etc.), il fat bien lire la doc de MS qui renvoie aux définitions de chaque version, car tu peux avoir des version de dll différentes dans certains cas.
Il faudra adapter le code suivant à tes besoins, en particulier faire un et logique tel qu'il est fait dans la procedure Themes_Disponibles() afin de ne pas prendre en compte les 2 paramètres wBuild.w, Qfe.w de la procedure MakeDllVerUll (qui pourrait être une macro)
La procedure Themes_Disponibles() retourne #true si les thèmes XP sont disponible sinon #false
Il permet de retrouver la version de la Dll (enfin je n'ai fait des tests que sur certaines dll qui gère les contrôles)
A savoir que la fonction DllGetVersion n'est pas une API mais est implémentée dans chaque Dll à partir des version 4.71; dans mon code je termine l'application si on a une version inférieure à 4.71 (à adapter au besoin)
(This function is not an application programming interface (API). It is exported by name from each DLL that implements it. Currently, most of the Windows Shell and common controls DLLs implement DllGetVersion. These include, but are not limited to, Shell32.dll, Comctl32.dll, Shdocvw.dll, and Shlwapi.dll.)
La doc dit aussi :
Minimum operating systems Windows 2000, Windows NT 4.0 with Internet Explorer 4.0, Windows 98
Si tu testes sur les dll permettant d'utiliser des fonctions pour les contrôles (ListIcon, Tree, Panel etc.), il fat bien lire la doc de MS qui renvoie aux définitions de chaque version, car tu peux avoir des version de dll différentes dans certains cas.
Il faudra adapter le code suivant à tes besoins, en particulier faire un et logique tel qu'il est fait dans la procedure Themes_Disponibles() afin de ne pas prendre en compte les 2 paramètres wBuild.w, Qfe.w de la procedure MakeDllVerUll (qui pourrait être une macro)
La procedure Themes_Disponibles() retourne #true si les thèmes XP sont disponible sinon #false
Code : Tout sélectionner
Structure DllVersionInfo_2 Extends DllVersionInfo
dwFlags.l
ullVersion.q
EndStructure
#Erreur = -1
Enumeration
#Inferieur_V_4_71 = 1 ; énumeration version Shell32.dll
#V_4_71
#V_4_72
#V_5_00
#V_6_00
#Superieur_V_6_00
EndEnumeration
; #Shlwapi_dll = "Shlwapi.dll"
#Shell32_dll = "Shell32.dll"
#Comctl32_dll = "Comctl32.dll"
Procedure.q MakeDllVerUll(wMajorVersion.w, wMinorVersion.w, wBuild.w, Qfe.w)
; retourne un quad permettant de comparer les versions des Dll
; ( par exemple Shell32.dll )
; ce quad est construit à partir de 4 valeurs
; Si on veut tester que la version 4.71 de la Dll Shell32.dll existe est supérieure ou
; égale à 4.71, il faut utiliser le code suivant ou wMajorVersion vaut 7 et wMinorVersion vaut 71
;
; If Dll_Version() >= MakeDllVerUll(4, 71, 0,0)
; ici la Dll a une version supérieure à 4,71
; Else
; ici la Dll a une version inférieure à 4,71
; EndIf
ProcedureReturn(wMajorVersion << 48) | (wMinorVersion << 32) | (wBuild << 16) | Qfe
EndProcedure
Procedure.q Dll_Version(Dll_Names.s)
; La fonction retourne un quad qui identifie la version de la Dll
; 'Shell32.dll' ou autre
Protected AddresseFonction.l, Dll.DllVersionInfo_2
Dll.DllVersionInfo_2\cbSize = SizeOf(DllVersionInfo_2)
If OpenLibrary(0, Dll_Names)
AddresseFonction = GetFunction(0, "DllGetVersion")
If addresseFonction
CallFunctionFast(addresseFonction, @dll)
CloseLibrary(0)
ProcedureReturn Dll\ullVersion
EndIf
EndIf
ProcedureReturn #Erreur
EndProcedure
Procedure.l Themes_Disponibles()
; retourne #True si les themes XP sont diposnibles sinon #False
Protected Version.q
version = Dll_Version(#Comctl32_dll) & $FFFFFFFF00000000
If (version <> - 1) And (version >= MakeDllVerUll(6, 0, 0, 0)) Or (OSVersion() = #PB_OS_Windows_Server_2003 And (version >= MakeDllVerUll(5, 1, 0, 0)))
ProcedureReturn #True
Else
ProcedureReturn #False
EndIf
EndProcedure
Global Version.q, VersionCourte.q
Version = Dll_Version(#Shell32_dll)
VersionCourte = Version & $FFFFFFFF00000000
If Version = -1 ; on a une version inférieur à 4.71 (Internet Explorer 4.0), l'API GetVersion n'existe pas
MessageRequester("Erreur dans l'application", "La version d'Internet Explorer est trop ancienne " + Chr(10) + "pour que l'application fonctionne correctement." + Chr(10) + Chr(10) + "Installer une version plus récente et réessayez." + Chr(10) + Chr(10) + "L'application va se terminer.", 16)
End
ElseIf (VersionCourte >= MakeDllVerUll(4, 71, 0, 0)) And (VersionCourte < MakeDllVerUll(4, 72, 0, 0))
Version = #V_4_71
Debug " Version de Shell32.dll : 4.71"
ElseIf (VersionCourte >= MakeDllVerUll(4, 72, 0, 0)) And (VersionCourte < MakeDllVerUll(5, 00, 0, 0))
Version = #V_4_72
Debug " Version de Shell32.dll : >= 4.72 et < 5.00"
ElseIf (VersionCourte >= MakeDllVerUll(5, 0, 0, 0)) And (VersionCourte < MakeDllVerUll(6, 0, 0, 0))
Version = #V_5_00
Debug " Version de Shell32.dll : >= 5.00 et < 6.00"
ElseIf (VersionCourte >= MakeDllVerUll(6, 00, 0, 0))
Version = #V_6_00
Debug " Version de Shell32.dll : 6.00"
Else
Version = #Superieur_V_6_00
Debug " Version de Shell32.dll : > 6.00"
EndIf
- Progi1984
- Messages : 2659
- Inscription : mar. 14/déc./2004 13:56
- Localisation : France > Rennes
- Contact :
J'ai trouvé ca :
ici > http://www.purebasic.fr/english/viewtop ... ersioninfo
Code : Tout sélectionner
Procedure.s GetFileVersionInfo(File.s)
Protected iLibrary.l, iFunctionInfo.l, iFunctionSize.l, iFunctionQry.l, *HoldVersion.l, HoldResult.l, HoldBuffer.l, HoldEmpty.l
Protected HoldString.s, HoldReturn.s
Protected *HoldInfo.VS_FIXEDFILEINFO
iLibrary = OpenLibrary(#PB_Any, "version.dll")
If iLibrary
iFunctionInfo = GetFunction(iLibrary, "GetFileVersionInfoA")
iFunctionSize = GetFunction(iLibrary, "GetFileVersionInfoSizeA")
iFunctionQry = GetFunction(iLibrary, "VerQueryValueA")
If iFunctionInfo And iFunctionSize And iFunctionQry
HoldBuffer = CallFunctionFast(iFunctionSize, @File, @HoldEmpty)
HoldReturn = Space(HoldBuffer)
HoldResult = CallFunctionFast(iFunctionInfo, File, 0, HoldBuffer, @HoldReturn)
HoldResult = CallFunctionFast(iFunctionQry, @HoldReturn, "\", @HoldEmpty, @HoldBuffer)
*HoldInfo = AllocateMemory(SizeOf(VS_FIXEDFILEINFO))
CopyMemory(HoldEmpty, *HoldInfo, SizeOf(VS_FIXEDFILEINFO))
HoldString = Str(*HoldInfo\dwFileVersionMS >> 16 & $FFFF) + "." + Str(*HoldInfo\dwFileVersionMS & $FFFF) + "." + Str(*HoldInfo\dwFileVersionLS >> 16 & $FFFF) + "." + Str(*HoldInfo\dwFileVersionLS & $FFFF)
CloseLibrary(iLibrary)
FreeMemory(*HoldInfo)
HoldReturn = Space(0)
If HoldResult
ProcedureReturn HoldString
Else
ProcedureReturn ""
EndIf
EndIf
CloseLibrary(iLibrary)
EndIf
EndProcedure
Librairies & Applications : https://www.purebasic.fr/french/viewtop ... f=8&t=6220
Site Web : https://rootslabs.net
Site Web : https://rootslabs.net
J'ai amélioré la version du forum anglais de Xombie, pour le format unicode ou ASCII
pour faire un essai
pour faire un essai
Code : Tout sélectionner
GetFileVersionInfo("shell32.DLL")
Code : Tout sélectionner
Procedure.s GetFileVersionInfo(File.s)
; procedure de Xombie ici http://www.purebasic.fr/english/viewtopic.php?t=18853
; modifiée pour mon besoin
Protected iLibrary.l, iFunctionInfo.l, iFunctionSize.l, iFunctionQry.l
Protected HoldString.s, HoldReturn.s, *HoldVersion, HoldResult.l
Protected HoldBuffer.l, HoldEmpty.l, *HoldInfo.VS_FIXEDFILEINFO
iLibrary = OpenLibrary(#PB_Any, "version.dll")
If iLibrary
CompilerIf #PB_Compiler_Unicode
iFunctionInfo = GetFunction(iLibrary, "GetFileVersionInfoW")
iFunctionSize = GetFunction(iLibrary, "GetFileVersionInfoSizeW")
iFunctionQry = GetFunction(iLibrary, "VerQueryValueW")
CompilerElse
iFunctionInfo = GetFunction(iLibrary, "GetFileVersionInfoA")
iFunctionSize = GetFunction(iLibrary, "GetFileVersionInfoSizeA")
iFunctionQry = GetFunction(iLibrary, "VerQueryValueA")
CompilerEndIf
If iFunctionInfo And iFunctionSize And iFunctionQry
HoldBuffer = CallFunctionFast(iFunctionSize, @File, @HoldEmpty)
If HoldBuffer
HoldReturn = Space(HoldBuffer)
HoldResult = CallFunctionFast(iFunctionInfo, File, 0, HoldBuffer, @HoldReturn)
If HoldResult
HoldResult = CallFunctionFast(iFunctionQry, @HoldReturn, "\", @HoldEmpty, @HoldBuffer)
If HoldResult
*HoldInfo = AllocateMemory(SizeOf(VS_FIXEDFILEINFO))
CopyMemory(HoldEmpty, *HoldInfo, SizeOf(VS_FIXEDFILEINFO))
HoldString = Str(*HoldInfo\dwFileVersionMS >> 16 & $FFFF) + "." + Str(*HoldInfo\dwFileVersionMS & $FFFF) + "." + Str(*HoldInfo\dwFileVersionLS >> 16 & $FFFF) + "." + Str(*HoldInfo\dwFileVersionLS & $FFFF)
CloseLibrary(iLibrary)
FreeMemory(*HoldInfo)
If HoldResult
ProcedureReturn HoldString
Else
ProcedureReturn ""
EndIf
EndIf
EndIf
EndIf
EndIf
CloseLibrary(iLibrary)
EndIf
ProcedureReturn ""
EndProcedure