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

Registry read/write compiler warnings

ferrad1
New Contributor I
1,722 Views

I'm not sure why I am getting these warnings:

module m_registry

   use ifwin
   implicit none

   contains

      integer(LONG) function RegRead(sKeyName, sValueName, sValue) result(iSt)
      !DEC$ATTRIBUTES DLLEXPORT :: RegRead

      implicit none

      character*(*), intent(in ) :: sKeyName     ! name of the key, null terminated
      character*(*), intent(in ) :: sValueName   ! name of the value, null terminated
      character*(*), intent(out) :: sValue       ! retrieved value

      integer(DWORD)  :: iLen                    !
      integer(HANDLE) :: hKey                    !

      iLen = len(sValue)    
      iSt = RegOpenKeyEx(HKEY_LOCAL_MACHINE, sKeyName, 0, KEY_EXECUTE, loc(hKey))
      if(iSt == ERROR_SUCCESS) then
        iSt = RegQueryValueEx( hKey, sValueName, NULL, NULL, loc(sValue), loc(iLen) )
        if(iSt == ERROR_SUCCESS) then
          iSt = RegCloseKey(hKey)
        endif
      endif

      return
      end

      integer(LONG) function RegWrite(sKeyName, sValueName, sValue) result(iSt)
      !DEC$ATTRIBUTES DLLEXPORT :: RegWrite

      implicit none

      character*(*), intent(in) :: sKeyName      ! name of the key, null terminated
      character*(*), intent(in) :: sValueName    ! name of the value, null terminated
      character*(*), intent(in) :: sValue        ! value to store, null terminated

      integer(DWORD)  :: iLen                    !
      integer(HANDLE) :: hKey                    !

      iLen = len(sValue)    
      iSt = RegOpenKeyEx(HKEY_LOCAL_MACHINE, sKeyName, 0, KEY_ALL_ACCESS, loc(hKey))
      if(iSt /= ERROR_SUCCESS) then
        iSt = RegCreateKey(HKEY_LOCAL_MACHINE, sKeyName, LOC(hKey))
      endif

      if(iSt == ERROR_SUCCESS) then
        iSt = RegSetValueEx(hKey, sValueName, 0, REG_SZ, loc(sValue), iLen)
        if(iSt == ERROR_SUCCESS) then
          iSt = RegCloseKey(hKey)
        endif
      endif

      return
      end

end module m_registry

 

a.f90(21): warning #7320: Standard F2008 requires that the type AND type parameters of the actual argument be the same as the type AND type parameters of the dummy argument. [#80000002]
a.f90(45): warning #7320: Standard F2008 requires that the type AND type parameters of the actual argument be the same as the type AND type parameters of the dummy argument. [#80000002]
a.f90(47): warning #7320: Standard F2008 requires that the type AND type parameters of the actual argument be the same as the type AND type parameters of the dummy argument. [#80000002]
a.f90(8): warning #6843: A dummy argument with an explicit INTENT(OUT) declaration is not given an explicit value. [SVALUE]

- HKEY_LOCALMACHINE is 4 byte (LONG)

- sValue is given a value as far as I can tell

0 Kudos
1 Solution
Steve_Lionel
Honored Contributor III
1,694 Views

The problem with HKEY_LOCAL_MACHINE is that the hkey argument is declared as INTEGER(HANDLE) (HKEY in the C header), and HKEY_LOCAL_MACHINE is INTEGER(LONG). These functions allow you to pass either the address of a handle, or one of the custom names such as HKEY_LOCAL_MACHINE. In a 64-bit application, these don't match.

You can replace these with int(HKEY_LOCAL_MACHINE,HANDLE). I wondered whether the API wants these values sign-extended or not (since the values have bit 31 set), and a quick C++ test shows that it does.

View solution in original post

0 Kudos
14 Replies
GVautier
New Contributor II
1,713 Views

The error

a.f90(8): warning #6843: A dummy argument with an explicit INTENT(OUT) declaration is not given an explicit value. [SVALUE]

is normal. The compiler can't  know that the value of svalue is assigned in line 23 because loc(sValue) is used.

You must explicitly initialize sValue at entry with

svalue=0

or other value

0 Kudos
Steve_Lionel
Honored Contributor III
1,695 Views

The problem with HKEY_LOCAL_MACHINE is that the hkey argument is declared as INTEGER(HANDLE) (HKEY in the C header), and HKEY_LOCAL_MACHINE is INTEGER(LONG). These functions allow you to pass either the address of a handle, or one of the custom names such as HKEY_LOCAL_MACHINE. In a 64-bit application, these don't match.

You can replace these with int(HKEY_LOCAL_MACHINE,HANDLE). I wondered whether the API wants these values sign-extended or not (since the values have bit 31 set), and a quick C++ test shows that it does.

0 Kudos
ferrad1
New Contributor I
1,673 Views

Sorry I see you have removed the ZEXT() suggestion, that has fixed it, thanks.

0 Kudos
Steve_Lionel
Honored Contributor III
1,659 Views

I removed ZEXT because I think it's wrong. With ZEXT, the value the API sees is no longer identified as HKEY_LOCAL_MACHINE. It will compile OK, but run incorrectly.

0 Kudos
ferrad1
New Contributor I
1,656 Views

Although that now allows this file to be compiled warning-free, I get failures elsewhere in compiling other files.  The use of ifwin in this file seems to interfere for the definition of null() for some reason.  This file is now part of a DLL, util.dll, which is USE'd elsewhere in the code.  Here is the error I am getting in a file that has "use util":

   type(t_input_processor_control), pointer :: cx  => null()

F:\src\net\iprocessor.f90(57): error #6414: This PARAMETER constant name is invalid in this context. [NULL]
F:\src\net\iprocessor.f90(57): error #6678: When the target is an expression it must deliver a pointer result. [NULL]

0 Kudos
Steve_Lionel
Honored Contributor III
1,631 Views

Replace the USE IFWIN with:

USE IFWIN, NOTUSED => NULL

0 Kudos
ferrad1
New Contributor I
1,620 Views

Nope that didn't help, but it turns out the solution is not to name your module m_registry, which must with conflict something internal.

0 Kudos
Steve_Lionel
Honored Contributor III
1,618 Views

I can't think of why that would matter.

0 Kudos
ferrad1
New Contributor I
1,610 Views

Me neither.  But I went through a rigorous process of starting off with an empty file with an empty module called aaa, which linked ok, then I step by step added stuff towards my end file.  It was the name of the module that broke it.

0 Kudos
andrew_4619
Honored Contributor II
1,593 Views

IFor the record I did a dumpbin on the x64, advapi32.lib in the sdk and that does not have any "m_???" symbols defined so I too find your error a bit baffling. The ADVAPI module also has no relevant definitions.....

0 Kudos
Steve_Lionel
Honored Contributor III
1,578 Views

What was the error you got? Please show the complete and actual text of the linker error messages.

0 Kudos
ferrad1
New Contributor I
1,574 Views

I changed the name of my module back to m_registry, and then a rebuild all gives:

F:\net\input_processor.f90(57): error #6414: This PARAMETER constant name is invalid in this context. [NULL]
F:\net\input_processor.f90(57): error #6678: When the target is an expression it must deliver a pointer result. [NULL]
ifort: error #10298: problem during post processing of parallel object compilation
compilation aborted for F:\net\input_processor.f90 (code 1)

Here is the registry.f90 file:

 

 

module m_registry

   use ifwin

   implicit none

   private
   public RegRead
   public RegWrite

   contains

      integer(LONG) function RegRead(sKeyName, sValueName, sValue) result(iSt)
      !DEC$ATTRIBUTES DLLEXPORT :: RegRead

      implicit none

      character*(*), intent(in ) :: sKeyName     ! name of the key, null terminated
      character*(*), intent(in ) :: sValueName   ! name of the value, null terminated
      character*(*), intent(out) :: sValue       ! retrieved value

      integer(DWORD)  :: iLen                    !
      integer(HANDLE) :: hKey                    !
      integer(LPVOID), parameter :: ANULL = 0

      sValue = ' '
      iLen = len(sValue)    
      iSt = RegOpenKeyEx(int(HKEY_CURRENT_USER,HANDLE), sKeyName, 0, KEY_EXECUTE, loc(hKey))
      if(iSt == ERROR_SUCCESS) then
        iSt = RegQueryValueEx(hKey, sValueName, ANULL, ANULL, loc(sValue), loc(iLen))
        if(iSt == ERROR_SUCCESS) then
          iSt = RegCloseKey(hKey)
        endif
      endif

      return
      end

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

      integer(LONG) function RegWrite(sKeyName, sValueName, sValue) result(iSt)
      !DEC$ATTRIBUTES DLLEXPORT :: RegWrite

      implicit none

      character*(*), intent(in) :: sKeyName      ! name of the key, null terminated
      character*(*), intent(in) :: sValueName    ! name of the value, null terminated
      character*(*), intent(in) :: sValue        ! value to store, null terminated

      integer(DWORD)  :: iLen                    !
      integer(HANDLE) :: hKey                    !

      iLen = len(sValue)    
      iSt = RegOpenKeyEx(int(HKEY_CURRENT_USER,HANDLE), sKeyName, 0, KEY_ALL_ACCESS, loc(hKey))
      if(iSt /= ERROR_SUCCESS) then
        iSt = RegCreateKey(int(HKEY_CURRENT_USER,HANDLE), sKeyName, LOC(hKey))
      endif

      if(iSt == ERROR_SUCCESS) then
        iSt = RegSetValueEx(hKey, sValueName, 0, REG_SZ, loc(sValue), iLen)
        if(iSt == ERROR_SUCCESS) then
          iSt = RegCloseKey(hKey)
        endif
      endif

      return
      end

end module m_registry

 

 

If the module is called m_myregistry, I get no link errors.

Note that the file it has the compilation error in, is not related to the registry file.  It does "use util" and util.f90 has "use m_registry"

The line of the compilation error in that file is:

 

 

   type(t_input_processor_control), pointer :: cx  => null()

 

If I fiddle with other stuff in registry.f90 (such as renaming ANULL back to NULL or removing the private and public lines at the top, it fails in other files during the link, but always related to NULL.

 

 

0 Kudos
Steve_Lionel
Honored Contributor III
1,561 Views

Um - did you change the USE in the file with the error to the new name?

0 Kudos
ferrad1
New Contributor I
1,555 Views

Yes, but don't worry - all fixed.

I had two old m_registry.mod files lurking in 2 src locations, not sure why they were there (probably from a cmd line ifort I was playing with a few days ago). A clean doesn't find them as the mod files are created in a tmp directory.  But a compile will look in the src folder first, and finds them.

0 Kudos
Reply