- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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.
Link Copied
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Jugoslav,
Thank you. I used T_OSVERSIONINFO, as the EX version is not defined in the kernel32 interface.
Daniel.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
[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]

- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page