Created
November 4, 2022 10:36
-
-
Save Irwin1985/d7494473fddd598042ec63db8bac22d6 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
* ============================================================== * | |
* This sample reads an entry from your Registry | |
* ============================================================== * | |
* Local lcHLM As String, lcKey As String, lcEntry As String | |
* lcHLM = "HCU" | |
* lcKey = "Software\Microsoft\VisualFoxPro\9.0\Options" | |
* lcEntry = "EditorStringColor" | |
* ? GetValue(lcHLM, lcKey, lcEntry) | |
* ============================================================== * | |
&& ======================================================================== && | |
&& Function GetValue | |
&& ======================================================================== && | |
Function GetValue As Variant | |
Lparameters tcKey As String, tcSubKey As String, tcValue As String | |
tcValue = Evl(tcValue, "") | |
Local lnKey As Integer, lcSubKey As String, lcValue As String | |
#Define HKEY_USERS -2147483645 | |
#Define HKEY_LOCAL_MACHINE -2147483646 | |
#Define HKEY_CURRENT_USER -2147483647 | |
#Define HKEY_CLASSES_ROOT -2147483648 | |
Do Case | |
Case m.tcKey == "HCR" | |
lnKey = HKEY_CLASSES_ROOT | |
Case m.tcKey == "HLM" | |
lnKey = HKEY_LOCAL_MACHINE | |
Case m.tcKey = "HCU" | |
lnKey = HKEY_CURRENT_USER | |
Case m.tcKey = "HCR" | |
lnKey = HKEY_CLASSES_ROOT | |
Otherwise | |
lnKey = m.tcKey | |
Endcase | |
lcSubKey = m.tcSubKey | |
lcValue = m.tcValue | |
Return ReadFromRegistry(lnKey, lcSubKey, lcValue) | |
Endfunc | |
&& ======================================================================== && | |
&& Protected Function ReadFromRegistry | |
&& ======================================================================== && | |
Function ReadFromRegistry As Variant | |
Parameters tnKey As Integer, tcSubKey As String, tcValue As String | |
Declare Integer RegOpenKey ; | |
In Win32API ; | |
Integer nHKey , ; | |
String @cSubKey , ; | |
Integer @nResult | |
Declare Integer RegQueryValueEx ; | |
In Win32API ; | |
Integer nHKey , ; | |
String lpszValueName , ; | |
Integer dwReserved , ; | |
Integer @lpdwType , ; | |
String @lpbData , ; | |
Integer @lpcbData | |
Declare Integer RegCloseKey ; | |
In Win32API ; | |
Integer nHKey | |
Local ; | |
lnErrCode As Integer, ; | |
lnKeyHandle As Integer, ; | |
lpdwValueType As Variant, ; | |
lpbValue As Variant, ; | |
lpcbValueSize As Variant, ; | |
lpdwReserved As Variant | |
lnKeyHandle = 0 | |
lpdwReserved = 0 | |
lpdwValueType = 1 | |
lpbValue = "" | |
lnErrCode = RegOpenKey(tnKey, tcSubKey, @lnKeyHandle) | |
If Empty(lnErrCode) | |
lpcbValueSize = 1 | |
lnErrCode = RegQueryValueEx(lnKeyHandle, tcValue, lpdwReserved, @lpdwValueType, @lpbValue, @lpcbValueSize) | |
lpbValue = Space(lpcbValueSize) | |
lnErrCode = RegQueryValueEx(lnKeyHandle, tcValue, lpdwReserved, @lpdwValueType, @lpbValue, @lpcbValueSize) | |
=RegCloseKey(lnKeyHandle) | |
If Empty(lnErrCode) | |
lpbValue = Left(lpbValue, lpcbValueSize - 1) | |
Endif | |
Endif | |
Clear Dlls RegOpenKey, RegQueryValueEx, RegCloseKey | |
Return lpbValue | |
Endfunc |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment