Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
How to write value to REG_DWORD(registry)
Message
From
31/01/2004 13:19:33
Cetin Basoz
Engineerica Inc.
Izmir, Turkey
 
 
To
31/01/2004 12:57:17
General information
Forum:
Visual FoxPro
Category:
Other
Miscellaneous
Thread ID:
00872666
Message ID:
00872668
Views:
164
>I am able to write to REG_SZ, but when i am changing it to write to REG_DWORD(32 bit number) i am getting error data type mismatch etc.
>
>Can you please change the following code to write to REG_DWORD instead of REG_SZ thank you very much.
>################################################################
>#define PATH_TO_MY_SUBKEY "Software\aaa_test"
>
>#define HKEY_CLASSES_ROOT ( 2147483648 )
>#define HKEY_CURRENT_USER ( 2147483649 )
>#define HKEY_LOCAL_MACHINE ( 2147483650 )
>#define HKEY_USERS ( 2147483651 )
>
>DECLARE long RegCreateKeyA in advapi32 AS RegCreate long hkey, string subkey, long @phkey
>* Creates or opens registry subkey
>DECLARE long RegOpenKeyA in advapi32 AS RegOpen long hkey, string subkey, long @phkey
>* Opens registry subkey
>
>
>#define REG_NONE ( 0 ) && No value type
>#define REG_SZ ( 1 ) && Unicode nul terminated string
>#define REG_EXPAND_SZ ( 2 ) && Unicode nul terminated string
> && (with environment variable references)
>#define REG_BINARY ( 3 ) && Free form binary
>#define REG_DWORD ( 4 ) && 32-bit number
>#define REG_DWORD_LITTLE_ENDIAN ( 4 ) && 32-bit number (same as REG_DWORD)
>#define REG_DWORD_BIG_ENDIAN ( 5 ) && 32-bit number
>#define REG_LINK ( 6 ) && Symbolic Link (unicode)
>#define REG_MULTI_SZ ( 7 ) && Multiple Unicode strings
>#define REG_RESOURCE_LIST ( 8 ) && Resource list in the resource map
>#define REG_FULL_RESOURCE_DESCRIPTOR ( 9 ) && Resource list in the hardware description
>#define REG_RESOURCE_REQUIREMENTS_LIST ( 10 )
>
>
>DECLARE long RegSetValueEx in advapi32 AS RegSetValue;
> long hkey, string value, long reserved, long type, string data, long data_size
>
>
>Declare Integer RegQueryValueEx In advapi32 AS RegGetValue ;
> Integer hkey, String Value, Integer Reserved,;
> Integer @Type, String @Data, Integer @Data_size
>
>
>do set_value with "options1", "1"
>
>?get_value("options1")
>
>
>PROCEDURE get_value
>LPARAMETERS opt_name
>aaa = 0
>res = 0
>type = 0
>data = SPACE(101)
>data_size = 100
>IF RegOpen(HKEY_LOCAL_MACHINE, PATH_TO_MY_SUBKEY, @aaa)=0
> =RegGetValue(m.aaa, m.opt_name, @res, @type, @data, @data_size)
> =RegClose(m.aaa)
>ENDIF
>RETURN LEFT(m.data, m.data_size-1)
>
>
>PROCEDURE set_value
>PARAMETERS opt_name, value
>aaa = 0
>IF RegCreate(HKEY_LOCAL_MACHINE, PATH_TO_MY_SUBKEY, @aaa)=0
> =RegSetValue(aaa, m.opt_name, 0, REG_SZ, m.value, LEN(m.value)+1)
> =RegClose(aaa)
> RETURN .T.
>ENDIF
>RETURN .F.
>######################################################################

Hope this helps :
#Define HKEY_CLASSES_ROOT           -2147483648
#Define HKEY_CURRENT_USER           -2147483647
#Define HKEY_LOCAL_MACHINE          -2147483646
#Define HKEY_USERS                  -2147483645

#Define REG_SZ 				1	&& String
#Define REG_BINARY 			3	&& Binary data
#Define REG_DWORD 			4	&& 32bits int

#Define ERROR_SUCCESS		0	&& OK

Declare Integer RegOpenKey In Win32API ;
  Integer nHKey, String @cSubKey, Integer @nResult
Declare Integer RegCloseKey In Win32API ;
  Integer nHKey
Declare Integer RegSetValueEx In Win32API ;
  Integer hKey, String lpszValueName, Integer dwReserved,;
  Integer fdwType, String lpbData, Integer cbData
Declare Integer RegQueryValueEx In Win32API ;
  Integer nHKey, String lpszValueName, Integer dwReserved,;
  Integer @lpdwType, String @lpbData, Integer @lpcbData
Declare RtlMoveMemory In WIN32API ;
  INTEGER @DestNumeric, ;
  STRING @pVoidSource, ;
  INTEGER nLength


Local lnCurValue,lcSubKey, lcOption
lcSubKey = 'Console'
lcOption = 'NumberOfHistoryBuffers'
lnCurValue = DWORD_GetRegValue(HKEY_CURRENT_USER, lcSubKey, lcOption)
If !IsNull(lnCurValue)
	? 'Current value',lnCurValue
	DWORD_SetRegValue(HKEY_CURRENT_USER, lcSubKey, lcOption,15)
	? 'After set',DWORD_GetRegValue(HKEY_CURRENT_USER, lcSubKey, lcOption)
	DWORD_SetRegValue(HKEY_CURRENT_USER, lcSubKey, lcOption,lnCurValue)
	? 'After restore',DWORD_GetRegValue(HKEY_CURRENT_USER, lcSubKey, lcOption)
endif

Function DWORD_GetRegValue
Lparameters tnRegRoot, tcSubKey, tcOption
Local lnKeyHandle,lpdwType,lpcbData,lpbData,lnValue

m.lnKeyHandle = 0
m.lpdwType = REG_DWORD
m.lpcbData = 4
m.lpbData = Replicate(Chr(0),4)
m.lnValue=0

If ( RegOpenKey(tnRegRoot, tcSubKey, @lnKeyHandle) = ERROR_SUCCESS )
  RegQueryValueEx(m.lnKeyHandle,tcOption, 0,@lpdwType,@lpbData,@lpcbData)
  RtlMoveMemory(@lnValue, lpbData, 4)
  RegCloseKey(m.lnKeyHandle)
  Return m.lnValue
Else
  Return .null.
EndIf
EndFunc

Function DWORD_SetRegValue
Lparameters tnRegRoot, tcSubKey, tcOption, tnValue
Local lnKeyHandle,lpdwType,lpcbData,lpbData

m.lnKeyHandle = 0
m.lpdwType = REG_DWORD
m.lpcbData = 4
m.lpbData = Num2Char(tnValue,4)

If ( RegOpenKey(tnRegRoot, tcSubKey, @lnKeyHandle) = ERROR_SUCCESS )
  RegSetValueEx(m.lnKeyHandle,tcOption, 0,@lpdwType,@lpbData,@lpcbData)
  RegCloseKey(m.lnKeyHandle)
EndIf
endfunc

Function Num2Char
lparameters tnNum, tnSize
Local ix,lcnum
lcNum = ''
For ix=1 to tnSize
	lcNum = lcNum + Chr(int(tnNum/(256^(ix-1)))%256)
endfor
return lcNum
endfunc
PS:Only changing the declaration was sufficient for your other thread.
Cetin
Çetin Basöz

The way to Go
Flutter - For mobile, web and desktop.
World's most advanced open source relational database.
.Net for foxheads - Blog (main)
FoxSharp - Blog (mirror)
Welcome to FoxyClasses

LinqPad - C#,VB,F#,SQL,eSQL ... scratchpad
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform