Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to create 'DWORD Value' in registry? 2

Status
Not open for further replies.

PankajAgr

Technical User
Jul 30, 2003
52
0
0
IN
Hi Guys,

I want to create 'DWORD' type of value in registry. I am using the following command to create the value in registry-

DECLARE Integer RegCreateKey IN Win32API ;
Integer nHKey, String @cSubKey, Integer @nResult

DECLARE Integer RegSetValueEx IN Win32API ;
Integer hKey, String lpszValueName, Integer dwReserved,Integer fdwType, String @lpbData, Integer cbData

#DEFINE HKEY_CURRENT_USER 2147483649

=RegCreateKey(HKEY_CURRENT_USER,"System\Policies",@hKey)
=RegSetValueEx(hKey,"Testing",0,4,"1",10)
=RegCloseKey(hkey)

These commands are creating the DWORD type of value but data part is showing "Invalid DWORD Value".

I want to know how to pass the right DWORD type of value to registry?

Thanks in advance.

Pankaj

Senior Software Engineer,
Infotech Enterprises Limited
Hyderabad, Andhra Pradesh, India.
URL :
 
Hi Pankaj.

Maybe this code will help:

Code:
********************************************************************
  *** FOXTOREG(): Convert VFP Data to Registry Equivalents
  ********************************************************************
  FUNCTION FoxToReg( tuValue, tnType )
  LOCAL lcRegVal, lnCnt
  IF VARTYPE( tuValue ) = "N" 
    *** Need to format this up as a double word string
    lcRegVal = ""
    FOR lnCnt = 24 TO 0 STEP -8
      *** Get the value for each byte
      lcRegVal = CHR( INT( tuValue / ( 2^lnCnt ) ) ) + lcRegVal
      *** Now we just need the remainder
      tuValue = MOD( tuValue, ( 2^lnCnt ) )
    NEXT
    *** Set the correct data type
    tnType = 4  && Constant Name = REG_DWORD
  ELSE
    *** Strings must be null-terminated
    lcRegVal = tuValue + CHR(0)
    tnType = 1  && Constant Name = REG_SZ
  ENDIF
  RETURN lcRegVal

Call the function like so:

Code:
*** Convert data and set datatype and length correctly
tuValue = .FoxToReg( tuValue, @lnDType, @lnValueSize )
lnValueSize = LEN( tuValue )
      
*** Try and set the value here
lnStatus = RegSetValueEx( This.nCurrentKey, tcKeyName, 0, lnDType, tuValue, lnValueSize)



Marcia G. Akins
 
Hi MarciaAkins,

Thanks for this valuable suggestion.

This code solved my problem.

* for you.

Pankaj

Senior Software Engineer,
Infotech Enterprises Limited
Hyderabad, Andhra Pradesh, India.
URL :
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top