⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 reg_traits.hpp

📁 新版本TR1的stl
💻 HPP
📖 第 1 页 / 共 2 页
字号:

        if(ERROR_SUCCESS != res)
        {
            hkeyDup = NULL;
        }

        if(NULL != result)
        {
            *result = res;
        }

        return hkeyDup;
    }

    static result_type reg_open_key(hkey_type hkey, char_type const* sub_key_name, hkey_type *hkey_result, REGSAM samDesired = KEY_ALL_ACCESS)
    {
        return ::RegOpenKeyExA(hkey, sub_key_name, 0, samDesired, hkey_result);
    }

    static result_type reg_create_key(hkey_type hkey, char_type const* sub_key_name, hkey_type *hkey_result, REGSAM samDesired = KEY_ALL_ACCESS)
    {
        return ::RegCreateKeyExA(hkey, sub_key_name, 0, NULL, 0, samDesired, NULL, hkey_result, NULL);
    }

    static result_type reg_create_key(hkey_type hkey, char_type const* sub_key_name, hkey_type *hkey_result, ws_bool_t &bCreated, REGSAM samDesired = KEY_ALL_ACCESS)
    {
        DWORD       disposition;
        result_type res =   ::RegCreateKeyExA(hkey, sub_key_name, 0, NULL, 0, samDesired, NULL, hkey_result, &disposition);

        bCreated = (ERROR_SUCCESS == res) && (REG_CREATED_NEW_KEY == disposition);

        return res;
    }

    static result_type reg_delete_key(hkey_type hkey, char_type const* sub_key_name)
    {
        return ::RegDeleteKeyA(hkey, sub_key_name);
    }

    static result_type reg_query_value(hkey_type hkey, char_type const* valueName, ws_dword_t& valueType, void *data, size_type &cbData)
    {
        return ::RegQueryValueExA(hkey, valueName, NULL, &valueType, static_cast<LPBYTE>(data), reinterpret_cast<LPDWORD>(&cbData));
    }

    static result_type reg_set_value(hkey_type hkey, char_type const* valueName, ws_dword_t valueType, void const* data, size_type cbData)
    {
        return ::RegSetValueExA(hkey, valueName, 0, valueType, static_cast<BYTE const*>(data), static_cast<DWORD>(cbData));
    }

    static result_type reg_delete_value(hkey_type hkey, char_type const* valueName)
    {
        return ::RegDeleteValueA(hkey, valueName);
    }

    static result_type reg_query_info(  hkey_type       hkey,
                                        char_type       *key_class,
                                        size_type       *cch_key_class,
                                        ws_uint_t       *c_sub_keys,
                                        size_type       *cch_sub_key_max,
                                        size_type       *cch_key_class_max,
                                        ws_uint_t       *c_values,
                                        size_type       *cch_valueName_max,
                                        size_type       *cb_value_data_max,
                                        size_type       *cb_security_descriptor_max,
                                        time_type       *time_last_write)
    {
        return ::RegQueryInfoKeyA(hkey, key_class, reinterpret_cast<LPDWORD>(cch_key_class), NULL, reinterpret_cast<LPDWORD>(c_sub_keys), reinterpret_cast<LPDWORD>(cch_sub_key_max), reinterpret_cast<LPDWORD>(cch_key_class_max), reinterpret_cast<LPDWORD>(c_values), reinterpret_cast<LPDWORD>(cch_valueName_max), reinterpret_cast<LPDWORD>(cb_value_data_max), reinterpret_cast<LPDWORD>(cb_security_descriptor_max), time_last_write);
    }

    static result_type reg_enum_key(    hkey_type       hkey,
                                        ws_dword_t      index,
                                        char_type       *key_name,
                                        size_type       *cch_key_name,
                                        time_type       *time_last_write    =   NULL)
    {
        return ::RegEnumKeyExA(hkey, index, key_name, reinterpret_cast<LPDWORD>(cch_key_name), NULL, NULL, NULL, time_last_write);
    }

    static result_type reg_enum_key(    hkey_type       hkey,
                                        ws_dword_t      index,
                                        char_type       *key_name,
                                        size_type       *cch_key_name,
                                        char_type       *key_class,
                                        size_type       *cch_key_class,
                                        time_type       *time_last_write)
    {
        return ::RegEnumKeyExA(hkey, index, key_name, reinterpret_cast<LPDWORD>(cch_key_name), NULL, key_class, reinterpret_cast<LPDWORD>(cch_key_class), time_last_write);
    }

    static result_type reg_enum_value(  hkey_type       hkey,
                                        ws_dword_t      index,
                                        char_type       *valueName,
                                        size_type       *cch_valueName,
                                        ws_dword_t      *valueType,
                                        void            *data,
                                        size_type       &cbData)
    {
        return ::RegEnumValueA(hkey, index, valueName, reinterpret_cast<LPDWORD>(cch_valueName), NULL, valueType, reinterpret_cast<LPBYTE>(data), reinterpret_cast<LPDWORD>(&cbData));
    }

    static result_type reg_enum_value(  hkey_type       hkey,
                                        ws_dword_t      index,
                                        char_type       *valueName,
                                        size_type       *cch_valueName)
    {
        return ::RegEnumValueA(hkey, index, valueName, reinterpret_cast<LPDWORD>(cch_valueName), NULL, NULL, NULL, NULL);
    }
};

STLSOFT_TEMPLATE_SPECIALISATION
struct reg_traits<ws_char_w_t>
{
public:
    typedef ws_char_w_t         char_type;
    typedef ws_size_t           size_type;
    typedef ws_ptrdiff_t        difference_type;
    typedef HKEY                hkey_type;
    typedef reg_string_w_t      string_type;
    typedef FILETIME            time_type;
    typedef ws_long_t           result_type;

public:
    static char_type *str_n_copy(char_type *dest, char_type const* src, size_type cch)
    {
        return ::wcsncpy(dest, src, cch);
    }

#if 0
    static char_type *str_copy(char_type *dest, char_type const* src)
    {
        return ::lstrcpyW(dest, src);
    }

    static char_type *str_cat(char_type *dest, char_type const* src)
    {
        return ::lstrcatW(dest, src);
    }

    static ws_int_t str_compare(char_type const* s1, char_type const* s2)
    {
        return ::lstrcmpW(s1, s2);
    }
#endif /* 0 */

    static size_type str_len(char_type const* src)
    {
        return static_cast<size_type>(::lstrlenW(src));
    }

#if 0
    static char_type *ensure_subkey_end(char_type *path)
    {
        char_type   *end;

        for(end = path; *end != L'\0'; ++end)
        {}

        if( path < end &&
            *(end - 1) != L'\\')
        {
            *end        =   L'\\';
            *(end + 1)  =   L'\0';
        }

        return path;
    }
#endif /* 0 */

    static size_type expand_env_strings(char_type const* src, char_type *dest, size_type cch_dest)
    {
        return static_cast<size_type>(::ExpandEnvironmentStringsW(src, dest, static_cast<DWORD>(cch_dest)));
    }

    static hkey_type key_dup(hkey_type hkey, REGSAM samDesired, result_type *result = NULL)
    {
        hkey_type   hkeyDup;
        result_type res = ::RegOpenKeyExW(hkey, L"", 0, samDesired, &hkeyDup);

        if(ERROR_SUCCESS != res)
        {
            hkeyDup = NULL;
        }

        if(NULL != result)
        {
            *result = res;
        }

        return hkeyDup;
    }

    static result_type reg_open_key(hkey_type hkey, char_type const* sub_key_name, hkey_type *hkey_result, REGSAM samDesired = KEY_ALL_ACCESS)
    {
        return ::RegOpenKeyExW(hkey, sub_key_name, 0, samDesired, hkey_result);
    }

    static result_type reg_create_key(hkey_type hkey, char_type const* sub_key_name, hkey_type *hkey_result, REGSAM samDesired = KEY_ALL_ACCESS)
    {
        return ::RegCreateKeyExW(hkey, sub_key_name, 0, NULL, 0, samDesired, NULL, hkey_result, NULL);
    }

    static result_type reg_create_key(hkey_type hkey, char_type const* sub_key_name, hkey_type *hkey_result, ws_bool_t &bCreated, REGSAM samDesired = KEY_ALL_ACCESS)
    {
        DWORD       disposition;
        result_type res =   ::RegCreateKeyExW(hkey, sub_key_name, 0, NULL, 0, samDesired, NULL, hkey_result, &disposition);

        bCreated = (ERROR_SUCCESS == res) && (REG_CREATED_NEW_KEY == disposition);

        return res;
    }

    static result_type reg_delete_key(hkey_type hkey, char_type const* sub_key_name)
    {
        return ::RegDeleteKeyW(hkey, sub_key_name);
    }

    static result_type reg_query_value(hkey_type hkey, char_type const* valueName, ws_dword_t& valueType, void *data, size_type &cbData)
    {
        return ::RegQueryValueExW(hkey, valueName, NULL, &valueType, static_cast<LPBYTE>(data), reinterpret_cast<LPDWORD>(&cbData));
    }

    static result_type reg_set_value(hkey_type hkey, char_type const* valueName, ws_dword_t valueType, void const* data, size_type cbData)
    {
        return ::RegSetValueExW(hkey, valueName, 0, valueType, static_cast<BYTE const*>(data), static_cast<DWORD>(cbData));
    }

    static result_type reg_delete_value(hkey_type hkey, char_type const* valueName)
    {
        return ::RegDeleteValueW(hkey, valueName);
    }

    static result_type reg_query_info(  hkey_type       hkey,
                                        char_type       *key_class,
                                        size_type       *cch_key_class,
                                        ws_uint_t       *c_sub_keys,
                                        size_type       *cch_sub_key_max,
                                        size_type       *cch_key_class_max,
                                        ws_uint_t       *c_values,
                                        size_type       *cch_valueName_max,
                                        size_type       *cb_value_data_max,
                                        size_type       *cb_security_descriptor_max,
                                        time_type       *time_last_write)
    {
        return ::RegQueryInfoKeyW(hkey, key_class, reinterpret_cast<LPDWORD>(cch_key_class), NULL, reinterpret_cast<LPDWORD>(c_sub_keys), reinterpret_cast<LPDWORD>(cch_sub_key_max), reinterpret_cast<LPDWORD>(cch_key_class_max), reinterpret_cast<LPDWORD>(c_values), reinterpret_cast<LPDWORD>(cch_valueName_max), reinterpret_cast<LPDWORD>(cb_value_data_max), reinterpret_cast<LPDWORD>(cb_security_descriptor_max), time_last_write);
    }

    static result_type reg_enum_key(    hkey_type       hkey,
                                        ws_dword_t      index,
                                        char_type       *key_name,
                                        size_type       *cch_key_name,
                                        time_type       *time_last_write    =   NULL)
    {
        return ::RegEnumKeyExW(hkey, index, key_name, reinterpret_cast<LPDWORD>(cch_key_name), NULL, NULL, NULL, time_last_write);
    }

    static result_type reg_enum_key(    hkey_type       hkey,
                                        ws_dword_t      index,
                                        char_type       *key_name,
                                        size_type       *cch_key_name,
                                        char_type       *key_class,
                                        size_type       *cch_key_class,
                                        time_type       *time_last_write)
    {
        return ::RegEnumKeyExW(hkey, index, key_name, reinterpret_cast<LPDWORD>(cch_key_name), NULL, key_class, reinterpret_cast<LPDWORD>(cch_key_class), time_last_write);
    }

    static result_type reg_enum_value(  hkey_type       hkey,
                                        ws_dword_t      index,
                                        char_type       *valueName,
                                        size_type       *cch_valueName,
                                        ws_dword_t      *valueType,
                                        void            *data,
                                        size_type       &cbData)
    {
        return ::RegEnumValueW(hkey, index, valueName, reinterpret_cast<LPDWORD>(cch_valueName), NULL, valueType, reinterpret_cast<LPBYTE>(data), reinterpret_cast<LPDWORD>(&cbData));
    }

    static result_type reg_enum_value(  hkey_type       hkey,
                                        ws_dword_t      index,
                                        char_type       *valueName,
                                        size_type       *cch_valueName)
    {
        return ::RegEnumValueW(hkey, index, valueName, reinterpret_cast<LPDWORD>(cch_valueName), NULL, NULL, NULL, NULL);
    }
};

#endif /* STLSOFT_DOCUMENTATION_SKIP_SECTION */

/* ////////////////////////////////////////////////////////////////////// */

#ifndef _WINSTL_NO_NAMESPACE
# if defined(_STLSOFT_NO_NAMESPACE) || \
     defined(STLSOFT_DOCUMENTATION_SKIP_SECTION)
} // namespace winstl
# else
} // namespace winstl_project
} // namespace stlsoft
# endif /* _STLSOFT_NO_NAMESPACE */
#endif /* !_WINSTL_NO_NAMESPACE */

/* ////////////////////////////////////////////////////////////////////// */

#endif /* WINSTL_INCL_WINSTL_REGISTRY_HPP_REG_TRAITS */

/* ////////////////////////////////////////////////////////////////////// */

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -