- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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.
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.
Link Copied
2 Replies
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Solved: I just set sValue(iLen:) = ' '
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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
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
Reply
Topic Options
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page