Hi everybody,
We use some functions from Kernel32.dll to get a DLL version number. This have been always working until PB 12.5.2. But PB2017 R3 crashes when we call HeapFree fuction.
EXTERNAL FUNCTIONS CALLED:
Function long GetFileVersionInfoSize(string sFile, REF ulong uDummy) library "VERSION.DLL" alias for "GetFileVersionInfoSizeW"
Function long GetFileVersionInfo(REF string sFile, ulong uDummy, ulong uLen, ulong uPoint) LIBRARY "version.dll" alias for "GetFileVersionInfoW"
Function ulong VerQueryValue(ulong uPoint, string sValue, REF ulong uPoint, REF ulong uLen) library "VERSION.DLL" alias for "VerQueryValueW"
Subroutine CopyMemory(REF string sbytes, ulong lpbytes, ulong uLen) library "KERNEL32.DLL" ALIAS FOR "RtlMoveMemory"
Function ulong GetProcessHeap() Library "KERNEL32.DLL"
Function ulong HeapAlloc (ulong hMem, uint uFlags, ulong uBytes) Library "KERNEL32.DLL"
Function long HeapFree (ulong hMem, uint uFlags, ulong uMemPoint) Library "KERNEL32.DLL"
Function ulong strcpy (REF string lpString1, ulong lpString2) Library "KERNEL32.DLL" alias for "lstrcpyW"
OUR FUNCTION:
public function integer of_product_version (string p_product_name, ref string p_version_number);
string vlsQuery, vlsLangcodepage, vlsBytes = space(62556)
ulong vllDummy, vllSize, vllHMem, vllLpInfo, vllLpPoint, vllLen
long vllRet
vllSize = GetFileVersionInfoSize(p_product_name, vllDummy)
IF vllSize <= 0 THEN
return //file not found
END IF
// get process id
vllHMem = GetProcessHeap()
vllLpInfo = HeapAlloc(vllHMem, 0, vllSize)
//get pointer to product info
vllRet = GetFileVersionInfo(p_product_name, vllDummy, vllSize, vllLpInfo)
IF vllRet = 0 THEN
return //some error
END IF
vlsQuery = "\VarFileInfo\Translation"
vllLen = VerQueryValue(vllLpInfo, vlsQuery, vllLpPoint, vllLen)
CopyMemory(vlsBytes, vllLpPoint, vllLen)
vlsQuery = "\StringFileInfo\040904E4\FileVersion"
vllRet = VerQueryValue(vllLpInfo, vlsQuery, vllLpPoint, vllLen)
if vllRet <= 0 then
p_version_number = ""
return //some error
end if
p_version_number = space(vllLen)
strcpy(p_version_number, vllLpPoint)
HeapFree(vllHMem, 0, vllLpPoint) // PB CRASHES HERE!!!!!!!
return 1
Any ideas?
thanks for the code - it worked fine and is a neat solution.
But as always, there is a but - is there a way how to get the dates (e.g. created date) from the GetFileVersionInfo?
Thanks,
Kari
https://www.topwizprogramming.com/freecode_filesys.html