home *** CD-ROM | disk | FTP | other *** search
/ Chip 2002 February / Chip_2002-02_cd1.bin / sharewar / apaths / APSOURCE.ZIP / GetPString.c < prev    next >
C/C++ Source or Header  |  2001-03-26  |  2KB  |  72 lines

  1. /* GetPString - March 26th, 2001
  2. **
  3. **      Copyright (c) 1997-2001 by Gregory Braun. All rights reserved.
  4. **
  5. **      This function returns the value associated with the specified
  6. **      registry key.
  7. **
  8. **      Called:     section = Registry section to search.
  9. **                  label   = Value to look for.
  10. **                  def     = Default to return if not found.
  11. **                  value   = buffer to hold returned value.
  12. **                  size    = size of "buffer" above.
  13. **
  14. **      Returns:    TRUE upon success, or FALSE if an error exists.
  15. **
  16. **      Notes:      This routine searchs the following key:
  17. **
  18. **                      HKEY_LOCAL_MACHINE
  19. **                        Software
  20. **                          Microsoft
  21. **                            Windows
  22. **                              CurrentVersion
  23. **                                AppPaths
  24. **                                  Section
  25. **                                    Label
  26. **
  27. */
  28.  
  29.  
  30. #include "AppPaths.h"
  31.  
  32. extern BOOL far GetPString (LPCSTR section,LPCSTR label,LPCSTR def,LPSTR value,DWORD size)
  33. {
  34.     auto HKEY   key     = NULL;
  35.  
  36.     auto LONG   err;
  37.     auto DWORD  type;
  38.  
  39.     auto char   sub[PSTRING];
  40.  
  41.     wsprintf (sub,"%s\\%s",REGSTR_PATH_APPPATHS,section);
  42.  
  43.     err = RegOpenKeyEx (HKEY_LOCAL_MACHINE,
  44.                         sub,
  45.                         NIL,
  46.                         KEY_QUERY_VALUE,
  47.                         &key);
  48.  
  49.     if (err != ERROR_SUCCESS) {
  50.         lstrcpy (value,def);
  51.         return (TRUE);
  52.         }
  53.  
  54.     err = RegQueryValueEx (key,
  55.                            label,
  56.                            NIL,
  57.                            &type,
  58.                            (LPBYTE) value,
  59.                            &size);
  60.  
  61.     if (key) RegCloseKey (key);
  62.  
  63.     if (err != ERROR_SUCCESS) {
  64.         lstrcpy (value,def);
  65.         return (TRUE);
  66.         }
  67.  
  68.     return (TRUE);
  69. }
  70.  
  71. /* end of GetPString.c - written by Gregory Braun */
  72.