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

Get OS Version Number

Ilie__Daniel
Beginner
1,342 Views

Hello!

I am trying to write a routine, in Fortran,to extract the version number from the OS, using GetVersionEx. I get an error message saying that dummy argument is not the same type as the actual argument of this function. I defined the structure as shown below. I have very little experience with C++.

I would appreciate any suggestions you might have.

Kind regards,

Daniel.

subroutine find_windows_version(version)
use kernel32, only: GetVersionEx, DWORD, WORD, BYTE, BOOL
implicit none

! Passed arguments
integer, intent(out) :: version

! Local variables
integer(BOOL) :: iresult

! Define type for getting version info
type t_OSVersionInfoEx
integer(DWORD) :: dwOSVersionInfoSize
integer(DWORD) :: dwMajorVersion
integer(DWORD) :: dwMinorVersion
integer(DWORD) :: dwBuildNumber
integer(DWORD) :: dwPlatformId
character(len=128) :: szCSDVersion
integer(WORD) :: wServicePackMajor
integer(WORD) :: wServicePackMinor
integer(WORD) :: wSuiteMask
integer(BYTE) :: wProductType
integer(BYTE) :: wReserved
end type

! Declare variables only used in this routine
type(t_OSVersionInfoEx) :: full_versinfo

! size in bytes of data to acquire from getversionex command
full_versinfo%dwOSVersionInfoSize = sizeof(full_versinfo)

! Use Win32 routine to find windows version info
iresult = GetVersionEx(full_versinfo)

if( full_versinfo%dwPlatformId == 2 .and. &
full_versinfo%dwMajorVersion == 5 )then
version = 2000
else
version = 0
end if

end subroutine find_windows_version

0 Kudos
1 Solution
Jugoslav_Dujic
Valued Contributor II
1,342 Views
Quoting - Daniel I.

Hello!

I am trying to write a routine, in Fortran,to extract the version number from the OS, using GetVersionEx. I get an error message saying that dummy argument is not the same type as the actual argument of this function. I defined the structure as shown below. I have very little experience with C++.

The basic error is that you're declaring again type T_OSVersionInfoEx. It's already defined in DFWINTY (and visible through KERNEL32).

(Fortran FAQ: if you define a TYPE in two places within the same scope, with the same names and same components, they're NOT the same type.)

Get rid of your type declaration, and add T_OSVersionInfoEx to the ONLY list.

View solution in original post

0 Kudos
6 Replies
Jugoslav_Dujic
Valued Contributor II
1,343 Views
Quoting - Daniel I.

Hello!

I am trying to write a routine, in Fortran,to extract the version number from the OS, using GetVersionEx. I get an error message saying that dummy argument is not the same type as the actual argument of this function. I defined the structure as shown below. I have very little experience with C++.

The basic error is that you're declaring again type T_OSVersionInfoEx. It's already defined in DFWINTY (and visible through KERNEL32).

(Fortran FAQ: if you define a TYPE in two places within the same scope, with the same names and same components, they're NOT the same type.)

Get rid of your type declaration, and add T_OSVersionInfoEx to the ONLY list.

0 Kudos
Ilie__Daniel
Beginner
1,342 Views

Jugoslav,

Thank you. I used T_OSVERSIONINFO, as the EX version is not defined in the kernel32 interface.

Daniel.

0 Kudos
Jugoslav_Dujic
Valued Contributor II
1,342 Views
Quoting - Daniel I.

Jugoslav,

Thank you. I used T_OSVERSIONINFO, as the EX version is not defined in the kernel32 interface.

Daniel.

Ah I see. I did check superfluously, but EX is actually defined only in VerifyVersionInfo; there's no generic interface for GetVersionEx. Maybe VerifyVersionInfo will suit you better (according to MSDN), although it's more complicated to use?

0 Kudos
Kirill_Mavrodiev__In
1,342 Views
Hi,

Here is one workaround:

program main

! Get Windows Version Number

use ifwin

implicit none

integer :: i
type (T_OSVERSIONINFOEX) :: VerInfo

! ****** copied from kernel32.f90, with type of lpVersionInformation changed
! to T_OSVERSIONINFOEX

INTERFACE
FUNCTION myGetVersionEx( &
lpVersionInformation)
import
integer(BOOL) :: myGetVersionEx ! BOOL
!DEC$ ATTRIBUTES DEFAULT, STDCALL, DECORATE, ALIAS:'GetVersionExA' :: myGetVersionEx
!DEC$ ATTRIBUTES REFERENCE, ALLOW_NULL :: lpVersionInformation
TYPE (T_OSVERSIONINFOEX) lpVersionInformation ! LPOSVERSIONINFOA lpVersionInformation
END FUNCTION
END INTERFACE

!-----------------------------------------------------------------------

VerInfo%dwOSVersionInfoSize = sizeof(VerInfo)

! ************* GetVersionEx does not work with T_OSVERSIONINFOEX

i = myGetVersionEx(VerInfo) ! this line compiles
! i = GetVersionEx(VerInfo) ! this line gives a compile error

end program main

0 Kudos
Steven_L_Intel1
Employee
1,342 Views
The compiler provides a Win32Platform sample that demonstrates how to get this information, among other things.
0 Kudos
Paul_Curtis
Valued Contributor I
1,342 Views
[cpp]TYPE(T_OSVERSIONINFO) :: os  ! defined in IFWINTY.F90
INTEGER				  :: windows_version, rval

os%dwOSVersionInfoSize = SIZEOF(os)
rval = GetVersionEx (os)
windows_version = os%dwPlatformId

SELECT CASE (windows_version)
CASE (VER_PLATFORM_WIN32_WINDOWS)	!	Win95 and Win98
	
CASE (VER_PLATFORM_WIN32_NT)		!	WinNT, Win2K, WinXP, Vista
    SELECT CASE (os%dwMajorVersion)
    CASE (6)    ! Vista or Longhorn
    CASE (5)    ! Win2000, WinXP
    END SELECT
	
END SELECT
[/cpp]

0 Kudos
Reply