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

Simple RegSetValue question

rahzan
Novice
965 Views
In the code below the regsetvalueex call results in an access viol error. Any guesses on the problem will be appreciated?

use dfwin
implicit none
integer hKey , hNewOrOld, pathLen
integer(LONG) retval
character(100) path
retVal=RegCreateKeyEx(HKEY_CURRENT_USER, &
'Environment'C, 0,'REG_SZ'C, &
REG_OPTION_NON_VOLATILE, KEY_ALL_ACCESS, &
NULL, loc(hKey), &
loc(hNewOrOld))

path='c:\hh'
pathLen=len_trim(path)+1
path(pathLen:pathLen)=char(0)
retVal=RegSetValueEx(hKey, 'HedgeHog'C, 0, &
REG_SZ, loc(path), loc(pathLen))

retVal=RegCloseKey(hKey)
4 Replies
james1
Beginner
965 Views
Eliminate the LOC on the last actual argument in the RegSetValueEx, it isn't expecting an address.

James
0 Kudos
rahzan
Novice
965 Views
Thank you James,
I don't know how I missed that, but a related question:

As you can see the arg "lpValueName" ('HEDGEHOG'C) is supposed to be a "Pointer to a string"
and the arg. "lpData" (=path) is supposed to be a "Pointer to a buffer". Now I don't know what a "buffer" is but is _looks like that it is a string as well.

Yet, I cannot seem to put in an explicit specification like 'c:h'C. (fials on compile: mismatch arg type)

Any idea why?

Thanks again,
TimH
0 Kudos
james1
Beginner
965 Views
Should work if you put it inside a LOC.

James
0 Kudos
Steven_L_Intel1
Employee
965 Views
Because the "buffer" for RegSetValueEx can be of any type, what you must pass from Fortran is the address of the buffer, or loc(buffer). The value name ("HEDGEHOG"C) is just a string that can be passed directly.

Steve
0 Kudos
Reply