Community
cancel
Showing results for 
Search instead for 
Did you mean: 
ferrad1
Novice
238 Views

Registry read/write compiler warnings

Jump to solution

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

Tags (1)
0 Kudos
1 Solution
Steve_Lionel
Black Belt Retired Employee
210 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

14 Replies
GVautier
New Contributor II
229 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

Steve_Lionel
Black Belt Retired Employee
211 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

ferrad1
Novice
189 Views

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

Steve_Lionel
Black Belt Retired Employee
175 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.

ferrad1
Novice
172 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]

Steve_Lionel
Black Belt Retired Employee
147 Views

Replace the USE IFWIN with:

USE IFWIN, NOTUSED => NULL

ferrad1
Novice
136 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.

Steve_Lionel
Black Belt Retired Employee
134 Views

I can't think of why that would matter.

ferrad1
Novice
126 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.

andrew_4619
Valued Contributor III
109 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.....

Steve_Lionel
Black Belt Retired Employee
94 Views

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

ferrad1
Novice
90 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.

 

 

Steve_Lionel
Black Belt Retired Employee
77 Views

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

ferrad1
Novice
71 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.

Reply