Intel® Fortran Compiler
Build applications that can scale for the future with optimized code designed for Intel® Xeon® and compatible processors.
28528 Discussions

Accessing executable information at run time

tlillys
Beginner
531 Views
We perform a lot of Monte Carlo simulations with a legacy code that is constantly evolving. Reproducibility can be a problem when we revisit old results if we are not sure which version produced which results. Part of the solution is using version control software and better file management practices. As an additional precaution, I'd like to add information about the EXE that generated the results to an output file: name, time stamp, version information from resource file, etc, something to link the EXE with the result.

I've poked around a bit without success. Can any one lend me a clue?

Ted
0 Kudos
6 Replies
Jugoslav_Dujic
Valued Contributor II
531 Views
a) To insert a version info into your .exe: Insert/Resource/Version. Fill in appropriate fields as you wish.

b) To retrieve that version from the .exe file (you can access it manually from Explorer by clicking "Properties"). From the code, use GetFileVersionInfo. I found some C codes comp.os.ms-windows.programmer.win32. Search for "GetFileVersionInfo" there. (I didn't paste direct URLs here, since they are looong and tend to screw in the Forum). Sorry, I don't have Fortran equivalent at hand.

c) (Related with (a)) Take a look here for a Visual Studio macro which auto-increments version number.

HTH
Jugoslav

0 Kudos
tlillys
Beginner
531 Views
After looking to Win32, I can successfully call GetFileVersionInfoSize, but the next call to GetFileVersionInfo is failing and I can't find the cause. Even GetLastError says nothing is wrong.

The code and project are attached.
0 Kudos
Steven_L_Intel1
Employee
531 Views
I haven't looked at your code, but here's mine (used in CVF updates)

Steve

integer function get_version (filename, vinfo)
use version
use kernel32
implicit none
character*(*), intent(in) :: filename  ! Must be NUL-terminated
integer(2), dimension(4), intent(out) :: vinfo

type (T_VS_FIXEDFILEINFO) :: fileinfo
pointer (p_fileinfo, fileinfo)
integer version_info_size, version_info_pointer,ret, fv_length
integer(2) istat

vinfo = 0
	version_info_size = GetFileVersionInfoSize (filename,loc(ret))
	if (version_info_size .eq. 0) then
	  get_version = GetLastError()
	  if (get_version == 0) get_version = -1
	  return
	  end if
	version_info_pointer = malloc(version_info_size)
	ret = GetFileVersionInfo (filename,0,version_info_size,&
	  version_info_pointer)
	if (ret .eq. 0) then
		call free(version_info_pointer)
		get_version = ret
		return
		end if
	ret = VerQueryValue (version_info_pointer, &
	  ""C,loc(p_fileinfo),&
	  loc(fv_length))
	if (ret .eq. 0) then
		call free(version_info_pointer)
		get_version = ret
		return
		end if

vinfo(1) = ibits(fileinfo%DWFileVersionMS, 16, 16)
vinfo(2) = ibits(fileinfo%DWFileVersionMS, 0, 16)
vinfo(3) = ibits(fileinfo%DWFileVersionLS, 16, 16)
vinfo(4) = ibits(fileinfo%DWFileVersionLS, 0, 16)
call free(version_info_pointer)

get_version = 0
return
end function get_version
0 Kudos
james1
Beginner
531 Views
There may be better ways that are more automated depending on how you do things. One way is if you build things with makefiles to just have a little program that runs whenever you build that updates a common block with some relevant build data.

Another way is to just read the link time out of your executable which doesn't require anything special from the build process.

James
0 Kudos
tlillys
Beginner
531 Views
Thanks, Steve. This was the boost I needed.
Also, thanks SB extended to Jugoslav for your suggestions for the update macro.
Ted
0 Kudos
Jugoslav_Dujic
Valued Contributor II
531 Views
For the record, here's the version of the macro I improved and fixed a bit:
- it runs only for Release version
- it requires the .rc file to be currently open (i.e. expanded in ResourceView)

Jugoslav
0 Kudos
Reply