home *** CD-ROM | disk | FTP | other *** search
/ Tricks of the Windows Gam…ming Gurus (2nd Edition) / Disc2.iso / msdn_vcb / samples / vc98 / sdk / winbase / winnt / pop3 / param.c < prev    next >
Encoding:
C/C++ Source or Header  |  1997-10-05  |  3.5 KB  |  117 lines

  1.  
  2. /******************************************************************************\
  3. *       This is a part of the Microsoft Source Code Samples.
  4. *       Copyright (C) 1992-1997 Microsoft Corporation.
  5. *       All rights reserved. 
  6. *       This source code is only intended as a supplement to 
  7. *       Microsoft Development Tools and/or WinHelp documentation.
  8. *       See these sources for detailed information regarding the 
  9. *       Microsoft samples programs.
  10. \******************************************************************************/
  11.  
  12. //+---------------------------------------------------------------------------
  13. //
  14. //  File:       param.c
  15. //
  16. //  Contents:
  17. //
  18. //  Classes:
  19. //
  20. //  Functions:
  21. //
  22. //----------------------------------------------------------------------------
  23.  
  24. #include "pop3srvp.h"
  25. #pragma hdrstop
  26.  
  27. WCHAR   szParamPath[] = TEXT("System\\CurrentControlSet\\Services\\Pop3Srv\\Parameters");
  28. WCHAR   szMailDirValue[] = TEXT("Mail Directory");
  29. WCHAR   szLoggingValue[] = TEXT("Logging Level");
  30.  
  31. //+---------------------------------------------------------------------------
  32. //
  33. //  Function:   ReadParameters
  34. //
  35. //  Synopsis:   Read parameters from registry
  36. //
  37. //  Arguments:  (none)
  38. //
  39. //  History:    1-11-95   RichardW   Created
  40. //
  41. //  Notes:
  42. //
  43. //----------------------------------------------------------------------------
  44. BOOL
  45. ReadParameters(VOID)
  46. {
  47.     HKEY    hKey;
  48.     LONG    err;
  49.     DWORD   ValueType;
  50.     DWORD   SizeOfBuffer;
  51.  
  52.     if (err = RegOpenKey(HKEY_LOCAL_MACHINE, szParamPath, &hKey))
  53.     {
  54.         ReportServiceEvent(
  55.             EVENTLOG_ERROR_TYPE,
  56.             POP3EVENT_PARAMETER_MISSING,
  57.             0, NULL, 1, szParamPath);
  58.         DebugLog((DEB_ERROR, "Could not open key, %d\n", err));
  59.         return(FALSE);
  60.     }
  61.  
  62.     //
  63.     // Now, read the parameters from the key:
  64.     //
  65.  
  66.     SizeOfBuffer = MAX_PATH;
  67.     err = RegQueryValueEx(  hKey,               // Key that we opened
  68.                             szMailDirValue,     // Value that we want
  69.                             NULL,
  70.                             &ValueType,         // Receives value type
  71.                             (PUCHAR) BaseDirectory,      // Receives value
  72.                             &SizeOfBuffer );    // Size of buffer
  73.  
  74.     if (err || (ValueType != REG_SZ))
  75.     {
  76.         DebugLog((DEB_ERROR, "Error %d reading value\n", err));
  77.         ReportServiceEvent(
  78.             EVENTLOG_ERROR_TYPE,
  79.             POP3EVENT_PARAMETER_MISSING,
  80.             0, NULL, 1, szMailDirValue);
  81.         RegCloseKey(hKey);
  82.         return(FALSE);
  83.     }
  84.  
  85.     //
  86.     // Add a backslash, so life is easier later:
  87.     //
  88.     SizeOfBuffer = wcslen(BaseDirectory);
  89.     if (BaseDirectory[SizeOfBuffer - 1] != L'\\')
  90.     {
  91.         BaseDirectory[SizeOfBuffer++] = L'\\';
  92.         BaseDirectory[SizeOfBuffer] = L'\0';
  93.     }
  94.  
  95.     SizeOfBuffer = sizeof(DWORD);
  96.     err = RegQueryValueEx(  hKey,
  97.                             szLoggingValue,
  98.                             NULL,
  99.                             &ValueType,
  100.                             (PUCHAR) &LoggingLevel,
  101.                             &SizeOfBuffer );
  102.  
  103.     if (err || ValueType != REG_DWORD)
  104.     {
  105.         DebugLog((DEB_ERROR, "Error %d reading value\n", err));
  106.         ReportServiceEvent(
  107.             EVENTLOG_ERROR_TYPE,
  108.             POP3EVENT_PARAMETER_MISSING,
  109.             0, NULL, 1, szLoggingValue);
  110.         RegCloseKey(hKey);
  111.         return(FALSE);
  112.     }
  113.  
  114.     RegCloseKey(hKey);
  115.     return(TRUE);
  116. }
  117.