geterrormsg = "out of memory"
case 87
geterrormsg = "invalid parameter"
case 234
geterrormsg = "there is more data than the buffer has been allocated to hold."
case else
geterrormsg = "undefined error code: " & str$(lerrorcode)
end select
end function
function getstringvalue(subkey as string, entry as string)
call parsekey(subkey, mainkeyhandle)
if mainkeyhandle then
rtn = regopenkeyex(mainkeyhandle, subkey, 0, key_read, hkey) 'open the key
if rtn = error_success then 'if the key could be opened then
sbuffer = space(255) 'make a buffer
lbuffersize = len(sbuffer)
rtn = regqueryvalueex(hkey, entry, 0, reg_sz, sbuffer, lbuffersize) 'get the value from the registry
if rtn = error_success then 'if the value could be retreived then
rtn = regclosekey(hkey) 'close the key
sbuffer = trim(sbuffer)
getstringvalue = left(sbuffer, len(sbuffer) - 1) 'return the value to the user
else 'otherwise, if the value couldnt be retreived
getstringvalue = "error" 'return error to the user
if displayerrormsg = true then 'if the user wants errors displayed then
msgbox errormsg(rtn) 'tell the user what was wrong
end if
end if
else 'otherwise, if the key couldnt be opened
getstringvalue = "error" 'return error to the user
if displayerrormsg = true then 'if the user wants errors displayed then
msgbox errormsg(rtn) 'tell the user what was wrong
end if
end if
end if
end function
private sub parsekey(keyname as string, keyhandle as long)
rtn = instr(keyname, "\") 'return if "\" is contained in the keyname
if left(keyname, 5) <> "hkey_" or right(keyname, 1) = "\" then 'if the is a "\" at the end of the keyname then
msgbox "incorrect format:" + chr(10) + chr(10) + keyname 'display error to the user
exit sub 'exit the procedure
elseif rtn = 0 then 'if the keyname contains no "\"
keyhandle = getmainkeyhandle(keyname)
keyname = "" 'leave keyname blank
else 'otherwise, keyname contains "\"
keyhandle = getmainkeyhandle(left(keyname, rtn - 1)) 'seperate the keyname
keyname = right(keyname, len(keyname) - rtn)
end if
end sub
function createkey(subkey as string)
call parsekey(subkey, mainkeyhandle)
if mainkeyhandle then
rtn = regcreatekey(mainkeyhandle, subkey, hkey) 'create the key
if rtn = error_success then 'if the key was created then
rtn = regclosekey(hkey) 'close the key
end if
end if
end function
function setstringvalue(subkey as string, entry as string, value as string)
call parsekey(subkey, mainkeyhandle)
if mainkeyhandle then
rtn = regopenkeyex(mainkeyhandle, subkey, 0, key_write, hkey) 'open the key
if rtn = error_success then 'if the key was open successfully then
rtn = regsetvalueex(hkey, entry, 0, reg_sz, byval value, len(value)) 'write the value
if not rtn = error_success then 'if there was an error writting the value
if displayerrormsg = true then 'if the user wants errors displayed
msgbox errormsg(rtn) 'display the error