File "registry.inc"
Path: /nimoworld/inc/registry.inc
File size: 2.62 KB
MIME-type:
Charset: utf-8
'REGISTRY.INC
'General Purpose Registry Access
'Uses: win32api.inc
'Functions:
' DelRegValue(lpKey As Long,ByVal cMainkey As String, ByVal Key As String) As Long
' GetRegValue(lpKey As Long,ByVal cMainkey As String, ByVal Key As String) As String
' SetRegValue(lpKey As Long,ByVal cMainkey As String, ByVal Key As String, ByVal Setting As String) As Long
' DelRegKey(lpKey As Long, Key As String) Export As Long
FUNCTION DelRegValue(lpKey AS LONG,BYVAL cMainkey AS STRING, BYVAL Key AS STRING) AS LONG
ON ERROR RESUME NEXT
LOCAL RetCode AS LONG
LOCAL hKey AS LONG
DIM acMainkey AS ASCIIZ * 300
acMainkey = cMainkey
RetCode = RegOpenKeyEx(lpKey, acMainkey, 0&, %KEY_ALL_ACCESS, hKey)
IF RetCode = %ERROR_SUCCESS THEN
IF Key$ = "*" THEN Key$ = CHR$(0,0)
RetCode = RegDeleteValue(hKey, BYVAL STRPTR(Key$))
END IF
RegCloseKey hKey
FUNCTION = RetCode
END FUNCTION
FUNCTION GetRegValue(lpKey AS LONG,BYVAL cMainkey AS STRING, BYVAL Key AS STRING) AS STRING
ON ERROR RESUME NEXT
DIM RetCode AS LONG
DIM hKey AS LONG
DIM KeyNameA AS ASCIIZ * 256
DIM zTmp AS ASCIIZ * 256
DIM acMainKey AS ASCIIZ * 300
DIM ZZZ AS STRING
DIM szdat&, cbData&, KeyType&
acMainKey = cMainKey
RetCode = RegOpenKeyEx(lpKey, acMainkey, 0&, %KEY_ALL_ACCESS, hKey)
IF RetCode = %ERROR_SUCCESS THEN
IF Key$ = "*" THEN Key$ = CHR$(0,0)
szdat&=256
DIM zbuffer AS ASCIIZ*256
KeyNameA = Key
cbData& = SIZEOF(zTmp)
RetCode = RegQueryValueEx(BYVAL hKey, KeyNameA, BYVAL 0, KeyType&, zTmp, cbData&)
ZZZ = zTmp
FUNCTION = ZZZ
EXIT FUNCTION
END IF
FUNCTION = ""
END FUNCTION
FUNCTION SetRegValue(lpKey AS LONG,BYVAL cMainkey AS STRING, BYVAL Key AS STRING, BYVAL Setting AS STRING) AS LONG
ON ERROR RESUME NEXT
LOCAL hKey AS LONG
LOCAL Result AS LONG
LOCAL zText AS ASCIIZ * 2048
IF Key$ = "*" THEN Key$ = CHR$(0,0)
IF RegCreateKeyEx(lpKey, cMainKey + CHR$(0),0, "", %REG_OPTION_NON_VOLATILE, _
%KEY_ALL_ACCESS, BYVAL %NULL, hKey, Result) <> %ERROR_SUCCESS THEN
FUNCTION = 0
EXIT FUNCTION
END IF
zText = Setting
IF LEN(Setting) THEN
RegSetValueEx hKey, Key+CHR$(0), 0, %REG_SZ, zText, LEN(Setting)+1
ELSE
RegSetValueEx hKey, Key+CHR$(0), 0, %REG_SZ, zText, 1
END IF
RegCloseKey hKey
FUNCTION = 0
END FUNCTION
FUNCTION DelRegKey(lpKey AS LONG, Key AS STRING) EXPORT AS LONG
ON ERROR RESUME NEXT
LOCAL zStrKey AS ASCIIZ * 255, hKey AS LONG, Result AS LONG
zStrKey = Key
IF RegOpenKeyEx(BYVAL lpKey,zStrKey,0, %KEY_ALL_ACCESS, hKey) <> %ERROR_SUCCESS THEN EXIT FUNCTION
Result = RegDeleteKey(lpKey, zStrKey)
RegCloseKey hKey
FUNCTION = Result
END FUNCTION