home *** CD-ROM | disk | FTP | other *** search
/ CD-ROM Today - The Disc! 2 / CD-ROM_Today_-_The_Disc_2_June-July_1994.iso / garden / setup / msregdb.inc < prev    next >
Text File  |  1993-11-18  |  4KB  |  130 lines

  1.  
  2.  
  3. '***************************************************************************
  4. '****************     registration database api's    ***********************
  5. '***************************************************************************
  6.  
  7. '$DEFINE REG_DB_ENABLED
  8.  
  9. const REG_SZ               = 1
  10. const HKEY_CLASSES_ROOT    = 1
  11. const ERROR_SUCCESS        = 0
  12.  
  13.  
  14. DECLARE FUNCTION EercErrorHandler LIB "mscomstf.dll" (grc%, fVital%, sz1$, sz2$, sz3$) AS INTEGER
  15. CONST GRC_API_FAILED       = 104
  16.  
  17. DECLARE FUNCTION RegOpenKey LIB "SHELL.DLL" (hKey&, szSubKey$, phkResult AS POINTER TO LONG) AS LONG
  18. DECLARE FUNCTION RegCreateKey LIB "shell.dll" (hKey&, szSubKey$, phkResult AS POINTER TO LONG) AS LONG
  19. DECLARE FUNCTION RegDeleteKey LIB "shell.dll" (hKey&, szSubKey$) AS LONG
  20. DECLARE FUNCTION RegCloseKey LIB "shell.dll" (hKey&) AS LONG
  21. DECLARE FUNCTION RegQueryValue LIB "shell.dll" (hKey&, szSubKey$, szValue$, lpcb AS POINTER TO LONG) AS LONG
  22. DECLARE FUNCTION RegSetValue LIB "shell.dll" (hKey&, szSubKey$, dwType&, szValue$, cbValue&) AS LONG
  23. DECLARE FUNCTION RegEnumKey LIB "shell.dll" (HkEY&, dwIndex&, szBuffer$, dwBufferSize&) AS LONG
  24.  
  25.  
  26. DECLARE SUB CreateRegKey(szKey$)
  27. DECLARE SUB CreateRegKeyValue(szKey$, szValue$)
  28. DECLARE SUB SetRegKeyValue(szKey$, szValue$)
  29. DECLARE SUB DeleteRegKey(szKey$)
  30. DECLARE FUNCTION GetRegKeyValue(szKey$) AS STRING
  31. DECLARE FUNCTION DoesRegKeyExist(szKey$) AS INTEGER
  32.  
  33.  
  34. 'NOTE: All keys are assumed to be subkeys of HKEY_CLASSES_ROOT. Therefore,
  35. 'the key HKEY_CLASSES_ROOT\key1\key2 would simply be written as key1\key2
  36. 'for these api's.
  37.  
  38.  
  39. '**************************************************************************
  40. SUB CreateRegKey(szKey$) STATIC
  41.     DIM phKey AS LONG
  42.  
  43.     IF RegCreateKey(HKEY_CLASSES_ROOT, szKey$, VARPTR(phKey)) > ERROR_SUCCESS THEN
  44.         i% = EercErrorHandler(GRC_API_FAILED, 1, "CreateRegKey", NULL, NULL)
  45. '$ifdef DEBUG
  46.         StfApiErr saeFail, "CreateRegKey", szKey$
  47. '$endif ''DEBUG
  48.         ERROR STFERR
  49.     END IF
  50.  
  51.     IF RegCloseKey(phKey) > ERROR_SUCCESS THEN
  52.         i% = EercErrorHandler(GRC_API_FAILED, 1, "CreateRegKey", NULL, NULL)
  53. '$ifdef DEBUG
  54.         StfApiErr saeFail, "CreateRegKey", szKey$
  55. '$endif ''DEBUG
  56.         ERROR STFERR
  57.     END IF
  58. END SUB
  59.  
  60.  
  61. '**************************************************************************
  62. SUB CreateRegKeyValue(szKey$, szValue$) STATIC
  63.     DIM phKey AS LONG
  64.  
  65.     IF RegSetValue(HKEY_CLASSES_ROOT, szKey$, REG_SZ,  szValue$, len(szKey$)) > ERROR_SUCCESS THEN
  66.         i% = EercErrorHandler(GRC_API_FAILED, 1, "CreateRegKeyValue", NULL, NULL)
  67. '$ifdef DEBUG
  68.         StfApiErr saeFail, "CreateRegKeyValue", szKey$+", "+szValue$
  69. '$endif ''DEBUG
  70.         ERROR STFERR
  71.     END IF
  72. END SUB
  73.  
  74.  
  75. '**************************************************************************
  76. FUNCTION DoesRegKeyExist(szKey$) STATIC AS INTEGER
  77.     DIM phKey AS LONG
  78.  
  79.     IF RegOpenKey(HKEY_CLASSES_ROOT, szKey$, VARPTR(phKey)) = ERROR_SUCCESS THEN
  80.         i = RegCloseKey(phKey)
  81.         DoesRegKeyExist = 1
  82.     ELSE
  83.         DoesRegKeyExist = 0
  84.     ENDIF
  85. END FUNCTION
  86.  
  87.  
  88. '**************************************************************************
  89. SUB SetRegKeyValue(szKey$, szValue$) STATIC
  90.     DIM phKey AS LONG
  91.  
  92.     IF RegSetValue(HKEY_CLASSES_ROOT, szKey$, REG_SZ,  szValue$, len(szKey$)) > ERROR_SUCCESS THEN
  93.         i% = EercErrorHandler(GRC_API_FAILED, 1, "SetRegKeyValue", NULL, NULL)
  94. '$ifdef DEBUG
  95.         StfApiErr saeFail, "SetRegKeyValue", szKey$+", "+szValue$
  96. '$endif ''DEBUG
  97.         ERROR STFERR
  98.     END IF
  99. END SUB
  100.  
  101.  
  102. '**************************************************************************
  103. FUNCTION GetRegKeyValue(szKey$) STATIC AS STRING
  104.     szValue$ = string$(512,32)
  105.     cb& = len(szValue$)
  106.  
  107.     IF DoesRegKeyExist(szKey$) = 0 THEN
  108.         GetRegKeyValue = ""
  109.         EXIT FUNCTION
  110.     END IF
  111.  
  112.     IF RegQueryValue(HKEY_CLASSES_ROOT, szKey$, szValue$, VARPTR(cb)) = ERROR_SUCCESS THEN
  113.         GetRegKeyValue = MID$(szValue$, 1, cb)
  114.     ELSE
  115.         i% = EercErrorHandler(GRC_API_FAILED, 1, "SetRegKeyValue", NULL, NULL)
  116. '$ifdef DEBUG
  117.         StfApiErr saeFail, "GetRegKeyValue", szKey$
  118. '$endif ''DEBUG
  119.         ERROR STFERR
  120.     END IF
  121.   szValue$ = ""
  122. END FUNCTION
  123.  
  124.  
  125. '**************************************************************************
  126. SUB DeleteRegKey(szKey$) STATIC
  127.     i& = RegDeleteKey(HKEY_CLASSES_ROOT, szKey$)
  128. END SUB
  129.  
  130.