PARAM.C
上传用户:bangxh
上传日期:2007-01-31
资源大小:42235k
文件大小:3k
源码类别:

Windows编程

开发平台:

Visual C++

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