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

Reading the registry - garbage after string

ferrad01
Beginner
406 Views
I am trying to read a string value from the registry, but I get a lot of garbage at the end of the string. Here is my code:

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

The registry key is:
SOFTWARE\\AspenTech\\Aprsystem\\26.0\\aplus

which contains:
"D:\\Program Files\\AspenTech\\APrSystem V7.3\\Engine"

However sValue is returned as:
"D:\\Program Files\\AspenTech\\APrSystem V7.3\\Engine h \\ A P r S y s t e m V 7 . 3 \\ E n g i n e "

It looks like it fills sValue with Unicode version of the string first, then overwrites the first part with the correct non-unicode version.
0 Kudos
2 Replies
ferrad01
Beginner
406 Views
Solved: I just set sValue(iLen:) = ' '
0 Kudos
Arjen_Markus
Honored Contributor I
406 Views
This is probably due to C using a terminating character (char(0)). The C routines treat a string
up to that character - without regard to the actual length - whereas Fortran uses the actual length
and considers the whole string. The left-over stuff you saw is not usually visible on the C side,
but it is on the Fortran side.

Regards,

Arjen
0 Kudos
Reply