Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
RegSetValueEx
Message
 
 
To
10/09/1998 13:04:30
General information
Forum:
Visual FoxPro
Category:
Windows API functions
Title:
Miscellaneous
Thread ID:
00135140
Message ID:
00135246
Views:
12
Mike,

Here's some of the code from my registry class:
<b>* method _SetKeyValue</b>

lparameters pcValueName, puValue
* this routine sets a key value

local lnValueSize, lcValue, lcValueType

this.mnErrorNum = ERROR_SUCCESS
lcValueType = type( "puValue" )

do case
   case ( this.mnCurrentKey = 0 )
      this.mnErrorNum = ERROR_BADKEY

   case ( type( "pcValueName" ) != "C" )
      this.mnErrorNum = ERROR_BADPARM

   case ( this.mnKeyType = REG_NONE )
      * new key, so set type according to puValue
      do case
         case ( lcValueType == "C" )
            this.mnKeyType = REG_SZ
         case ( lcValueType == "N" )
            this.mnKeyType = REG_DWORD
         otherwise
            this.mnErrorNum = ERROR_BADPARM
      endcase

   case ( ( lcValueType == "C" ) and ( this.mnKeyType != REG_SZ ) )
      this.mnErrorNum = ERROR_NONSTR_DATA

   case ( ( lcValueType == "N" ) and ( this.mnKeyType != REG_DWORD ) )
      this.mnErrorNum = ERROR_NONDWORD_DATA

   case empty( pcValueName ) and empty( puValue )
      this.mnErrorNum = ERROR_BADPARM
endcase

if ( this.mnErrorNum != ERROR_SUCCESS )
   return this.mnErrorNum
endif

* 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 )

if ( this.mnErrorNum == ERROR_SUCCESS )
   this.mnMaxValueDataLen = max( this.mnMaxValueDataLen, lnValueSize )
   * update the object properties
   this._GetKeyValue( pcValueName )
endif

return this.mnErrorNum


<b>*method _GetKeyValue</b>

lparameters pcValueName
* Obtains a value from a registry key

this.mnErrorNum = ERROR_SUCCESS

do case
   case ( this.mnCurrentKey = 0 )
      this.mnErrorNum = ERROR_BADKEY
   case ( type( "pcValueName" ) != "C" )
      this.mnErrorNum = ERROR_BADPARM
endcase

if ( this.mnErrorNum != ERROR_SUCCESS )
   return this.mnErrorNum
endif

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

return this.mnErrorNum

<b>* method _DecodeValue</b>
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 anything other types
endcase

return luRetVal
The functions ToLong and FromLong are available on my website under Q&A, General, Article qGEN003


>I'm trying to modify Registry.prg to allow writing a Registry entry as a number. I need to modify a parameter that is used by a 3rd party Communication program and I don't have any other options.
>
> changed the declaration for RegSetValueEx for the data parameter from String to Integer. I can successfully "write" to the registry, but when I use RegEdit to look at the value written, I get an "Invalid DWORD value" message. I've tried sending an 0x1 to write the value as a hex, but RegEdit shows me that it came through as 01 not 0x00000001(1). I've looked at the declaration in the Win32API.txt file and the data parameter type is defined "any".
>
>Is it possible that VFP can't write numeric values to the Registry? Any suggestions?
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