Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Modifying the registry
Message
General information
Forum:
Visual FoxPro
Category:
Windows API functions
Miscellaneous
Thread ID:
00205563
Message ID:
00205847
Views:
18
Rick,

Here's a chunk from my Registry class that should help:
* SetKey
...
* fix up the value to store in the registry
do case
   case ( this.mnKeyType = REG_SZ )
      * Make sure we null terminate this guy
      lcValue = puValue + chr(0)
      lnValueSize = len( lcValue )

   case ( this.mnKeyType = REG_DWORD )
      lcValue = ToLong( puValue )
      lnValueSize = 4
endcase

* Set the key value

this.mnErrorNum = RegSetValueEx( this.mnCurrentKey, @pcValueName, 0, this.mnKeyType, ;
                                 @lcValue, lnValueSize )
...

* GetKey
...
local lpdwReserved, lpdwtype, lcData, lnData
lpdwReserved = 0
lpdwtype = REG_NONE
lcData = space( this.mnMaxValueDataLen )
lnData = len( lcData )

this.mnErrorNum = RegQueryValueEx( this.mnCurrentKey, @pcValueName, @lpdwReserved, @lpdwType, ;
                                   @lcData, @lnData )
if ( this.mnErrorNum = ERROR_SUCCESS )
   this.mnKeyType = lpdwType
   this.muKeyValue = this._DecodeValue( lpdwType, lcData, lnData )
endif
...

* _DecodeValue
lparameter pdwType, pcData, pnData

local luRetVal

luRetVal = .null.

do case
   case pdwType = REG_SZ
      luRetVal = left( pcData, pnData-1 )

   case pdwType = REG_DWORD
      luRetVal = FromLong( pcData )

   case pdwType = REG_BINARY
      * provide read access to this type, but for registry safety reasons write is not supported
      luRetVal = left( pcData, pnData )

   otherwise
      * Don't support any other types
endcase

return luRetVal


* ConvertAPI.prg 08-Oct-97 

* these functions convert to/from internal binary storage

function ToWord( pnNumber )
local lnMSB, lnLSB
lnMSB = int( pnNumber / 256 )  && most significant byte
lnLSB = pnNumber % 256  && least significant byte
return chr( lnLSB ) + chr( lnMSB )

function ToLong( pnNumber )
local lnMSW, lnLSW
lnMSW = int( pnNumber / 65536 )  && most significant word
lnLSW = pnNumber % 65536  && least significant word
return ToWord( lnLSW ) + ToWord( lnMSW )

function FromWord( pcBuffer )
return asc( substr( pcBuffer, 2, 1 ) ) * 256 + asc( left( pcBuffer, 1 ) )

function FromLong( pcBuffer )
return FromWord( substr( pcBuffer, 3, 2 ) ) * 65536 + FromWord( left( pcBuffer, 2 ) )
>I've used the registry class that ships with VFP to modify registry keys. The basic API call used in the registry class is "RegSetValueEx". It works great on string values, however, I now need a method to modify a key stored as a hex value in the registry. The key appears as hex when accessed through regedit.exe - if you export the key from regedit to a .reg file, it is exported as a dword. Is anyone aware of a way to set a hex value in the registry, either through a VFP API call or a C call?
df (was a 10 time MVP)

df FoxPro website
FoxPro Wiki site online, editable knowledgebase
Previous
Reply
Map
View

Click here to load this message in the networking platform