/*****************************************************************************
* Copyright (c) 1990-98 Digi International Inc., All Rights Reserved
* 
* This software contains proprietary and confidential information of Digi
* International Inc.  By accepting transfer of this copy, Recipient agrees
* to retain this software in confidence, to prevent disclosure to others,
* and to make no use of this software other than that for which it was
* delivered.  This is an unpublished copyrighted work of Digi International
* Inc.  Except as permitted by federal law, 17 USC 117, copying is strictly
* prohibited.
* 
* Restricted Rights Legend
*
* Use, duplication, or disclosure by the Government is subject to
* restrictions set forth in sub-paragraph (c)(1)(ii) of The Rights in
* Technical Data and Computer Software clause at DFARS 252.227-7031 or
* subparagraphs (c)(1) and (2) of the Commercial Computer Software -
* Restricted Rights at 48 CFR 52.227-19, as applicable.
*
* Digi International Inc. 11001 Bren Road East, Minnetonka, MN 55343
*
*****************************************************************************/


#if !defined(REGHELPERS_H)

#define REGHELPERS_H
#if _MSC_VER >= 1000
#pragma once
#endif // _MSC_VER >= 1000


#if defined(RegCreateKey)
// NOTE:
//    We undef RegCreateKey because there is a Win32 API with the same name, but different
//    parameters.  RegCreateKey gets defined to RegCreateKeyA or RegCreateKeyW depending
//    on whether or not UNICODE is defined.  We don't want to have any sort of confusion
//    as to which function we're using here, so undef the old obsolete API.
#undef RegCreateKey
#endif

extern BOOL FW_EXPORTED_API RegCreateKey(HKEY const Key, CString const & strSubKey, HKEY * const phKey,
                                         DWORD const dwOptions = REG_OPTION_NON_VOLATILE,
                                         REGSAM const samDesired = KEY_ALL_ACCESS,
                                         DWORD * const pdwDisposition = NULL);

#if defined(RegOpenKey)
// NOTE:
//    We undef RegOpenKey because there is a Win32 API with the same name, but different
//    parameters.  RegOpenKey gets defined to RegOpenKeyA or RegOpenKeyW depending
//    on whether or not UNICODE is defined.  We don't want to have any sort of confusion
//    as to which function we're using here, so undef the old obsolete API.
#undef RegOpenKey
#endif

extern BOOL FW_EXPORTED_API RegKeyExists(HKEY const Key, CString const & strSubKey);
#define RegValueExists(k, n) (RegValueType((k), (n)) != REG_NONE)

extern BOOL FW_EXPORTED_API RegOpenKey(HKEY const Key, CString const & strSubKey, HKEY * const phKey,
                                       REGSAM const samDesired = KEY_ALL_ACCESS);

extern BOOL FW_EXPORTED_API RegDelKey(HKEY const Key, CString const & strSubKey);
extern BOOL FW_EXPORTED_API RegDelValue(HKEY const Key, CString const & ValueName);

extern DWORD FW_EXPORTED_API RegValueType(HKEY const Key, CString const & ValueName);
extern DWORD FW_EXPORTED_API RegValueSize(HKEY const Key, CString const & ValueName);

extern BOOL FW_EXPORTED_API RegEnumSubKeyNames(HKEY const Key, CStringArray & astrSubKeys);
extern BOOL FW_EXPORTED_API RegEnumValueNames(HKEY const Key, CStringArray & astrValues, DWORD const dwOnlyEnumType = REG_NONE);

typedef CMap<CString, TCHAR const * const, CString, CString&> CMapRegStrValues;
extern BOOL FW_EXPORTED_API RegEnumStrValues(HKEY const Key, CMapRegStrValues & mapValues);

typedef CMap<CString, TCHAR const * const, DWORD, DWORD&> CMapRegDWordValues;
extern BOOL FW_EXPORTED_API RegEnumDWordValues(HKEY const Key, CMapRegDWordValues & mapValues);

extern BOOL FW_EXPORTED_API RegReadStrValue(HKEY const Key, CString const & ValueName, CString & Value, CString const & Default = TEXT(""));
extern BOOL FW_EXPORTED_API RegWriteStrValue(HKEY const Key, CString const & ValueName, CString const & Value);

extern BOOL FW_EXPORTED_API RegReadSzValue(HKEY const Key, CString const & ValueName, TCHAR * const Value, DWORD const cchValue, TCHAR const * const Default = TEXT(""));
extern BOOL FW_EXPORTED_API RegWriteSzValue(HKEY const Key, CString const & ValueName, TCHAR const * const Value);

extern BOOL FW_EXPORTED_API RegReadExpandStrValue(HKEY const Key, CString const & ValueName, CString & Value, CString const & Default = TEXT(""));
extern BOOL FW_EXPORTED_API RegWriteExpandStrValue(HKEY const Key, CString const & ValueName, CString const & Value);

extern BOOL FW_EXPORTED_API RegReadExpandSzValue(HKEY const Key, CString const & ValueName, TCHAR * const Value, DWORD const cchValue, TCHAR const * const Default = TEXT(""));
extern BOOL FW_EXPORTED_API RegWriteExpandSzValue(HKEY const Key, CString const & ValueName, TCHAR const * const Value);

extern BOOL FW_EXPORTED_API RegReadIntValue(HKEY const Key, CString const & ValueName, int * const Value, int const Default = 0);
extern BOOL FW_EXPORTED_API RegWriteIntValue(HKEY const Key, CString const & ValueName, int const Value);

extern BOOL FW_EXPORTED_API RegReadDWordValue(HKEY const Key, CString const & ValueName, DWORD * const Value, DWORD const Default = 0);
extern BOOL FW_EXPORTED_API RegWriteDWordValue(HKEY const Key, CString const & ValueName, DWORD const Value);

extern BOOL FW_EXPORTED_API RegReadBoolValue(HKEY const Key, CString const & ValueName, BOOL * const Value, BOOL const Default = FALSE);
extern BOOL FW_EXPORTED_API RegWriteBoolValue(HKEY const Key, CString const & ValueName, BOOL const Value);

extern BOOL FW_EXPORTED_API RegReadBinaryValue(HKEY const Key, CString const & ValueName, BYTE * const Value, DWORD & cbValue, BYTE const Default = 0);
extern BOOL FW_EXPORTED_API RegWriteBinaryValue(HKEY const Key, CString const & ValueName, BYTE const * const Value, DWORD const cbValue);

extern BOOL FW_EXPORTED_API RegReadMultiStrValue(HKEY const Key, CString const & ValueName, CStringArray & Value, CStringArray const * const Default = NULL);
extern BOOL FW_EXPORTED_API RegWriteMultiStrValue(HKEY const Key, CString const & ValueName, CStringArray const & Value);

extern BOOL FW_EXPORTED_API RegReadMultiSzValue(HKEY const Key, CString const & ValueName, TCHAR * const Value, DWORD const cbValue, TCHAR const * const Default = TEXT(""));
extern BOOL FW_EXPORTED_API RegWriteMultiSzValue(HKEY const Key, CString const & ValueName, TCHAR const * const Value);

typedef struct
{
   TCHAR * pszName;
   void * pvData;
   DWORD cbData;
   DWORD dwType;
   void * pvDefault;
}
REGVALUE;

extern BOOL FW_EXPORTED_API RegReadMultipleValues(HKEY const Key, REGVALUE * const pRegVals, DWORD const cRegVals);
extern BOOL FW_EXPORTED_API RegWriteMultipleValues(HKEY const Key, REGVALUE const * const pRegVals, DWORD const cRegVals);

#endif // REGHELPERS_H
