Files
Include/EgtIniFile.h
T
Dario Sassi fdb711eea6 Include :
- aggiornamento prototipi.
2019-03-18 06:51:20 +00:00

91 lines
3.7 KiB
C++

//----------------------------------------------------------------------------
// EgalTech 2013-2019
//----------------------------------------------------------------------------
// File : EgtIniFile.h Data : 17.03.19 Versione : 2.1c2
// Contenuto : Funzioni per leggere e scrivere stringhe UTF-8 in file INI.
//
//
//
// Modifiche : 10.12.13 DS Creazione modulo.
//
//
//----------------------------------------------------------------------------
#pragma once
#include "/EgtDev/Include/EGnStringUtils.h"
#include "/EgtDev/Include/EgtStringConverter.h"
#include <Winbase.h>
//----------------------------------------------------------------------------
inline std::string
GetPrivateProfileStringUtf8( const char* szSection, const char* szKey, const char* szDefault, const char* szIniFile)
{
// leggo la stringa dal file INI come ANSI/UTF-8 in WChar e metto in Char
wchar_t szBuffW[_MAX_PATH] ;
int nChar = GetPrivateProfileStringW( AtoW( szSection), AtoW( szKey), NULL, szBuffW, _MAX_PATH, AtoW( szIniFile)) ;
if ( nChar <= 0)
return szDefault ;
return LPSTR( WtoAEX<>( szBuffW, CP_ACP)) ;
}
//----------------------------------------------------------------------------
inline std::string
GetPrivateProfileStringUtf8( const char* szSection, const char* szKey, const char* szDefault, const wchar_t* szIniFile)
{
// leggo la stringa dal file INI come ANSI/UTF-8 in WChar e metto in Char
wchar_t szBuffW[_MAX_PATH] ;
int nChar = GetPrivateProfileStringW( AtoW( szSection), AtoW( szKey), NULL, szBuffW, _MAX_PATH, szIniFile) ;
if ( nChar <= 0)
return szDefault ;
return LPSTR( WtoAEX<>( szBuffW, CP_ACP)) ;
}
//----------------------------------------------------------------------------
inline bool
WritePrivateProfileStringUtf8( const char* szSection, const char* szKey, const char* szVal, const char* szIniFile)
{
// salvo la stringa nel file INI come ANSI/UTF-8 ma scritta in variabile WChar
return WritePrivateProfileStringW( AtoW( szSection), AtoW( szKey), AtoWEX<>( szVal, CP_ACP), AtoW( szIniFile)) != 0 ;
}
//----------------------------------------------------------------------------
inline bool
WritePrivateProfileStringUtf8( const char* szSection, const char* szKey, const char* szVal, const wchar_t* szIniFile)
{
// salvo la stringa nel file INI come ANSI/UTF-8 ma scritta in variabile WChar
return WritePrivateProfileStringW( AtoW( szSection), AtoW( szKey), AtoWEX<>( szVal, CP_ACP), szIniFile) != 0 ;
}
//----------------------------------------------------------------------------
inline int
GetPrivateProfileInt( const char* szSection, const char* szKey, int nDefault, const char* szIniFile)
{
return GetPrivateProfileIntW( AtoW( szSection), AtoW( szKey), nDefault, AtoW( szIniFile)) ;
}
//----------------------------------------------------------------------------
inline int
GetPrivateProfileInt( const char* szSection, const char* szKey, int nDefault, const wchar_t* szIniFile)
{
return GetPrivateProfileIntW( AtoW( szSection), AtoW( szKey), nDefault, szIniFile) ;
}
//----------------------------------------------------------------------------
inline bool
WritePrivateProfileInt( const char* szSection, const char* szKey, int nVal, const char* szIniFile)
{
return WritePrivateProfileStringUtf8( szSection, szKey, ToString( nVal).c_str(), szIniFile) ;
}
//----------------------------------------------------------------------------
inline bool
WritePrivateProfileInt( const char* szSection, const char* szKey, int nVal, const wchar_t* szIniFile)
{
return WritePrivateProfileStringUtf8( szSection, szKey, ToString( nVal).c_str(), szIniFile) ;
}