//---------------------------------------------------------------------------- // EgalTech 2025-2025 //---------------------------------------------------------------------------- // File : IniFile.cpp Data : 24.01.25 Versione : 2.7a1 // Contenuto : Implementazione funzioni lettura/scrittura su INI file con UTF8. // // // Modifiche : 24.01.25 DS Creazione modulo. // // //---------------------------------------------------------------------------- //--------------------------- Include ---------------------------------------- #include "stdafx.h" #include "StringUtils.h" using namespace std ; //---------------------------------------------------------------------------- BOOL __stdcall EgtGetStringUtf8FromIni( const wchar_t* wsSec, const wchar_t* wsKey, const wchar_t* wsDef, wchar_t*& wsVal, const wchar_t* wsIniFile) { // leggo la stringa dal file INI come ANSI/UTF-8 in WChar e metto in Char wchar_t szBuffW[_MAX_PATH] ; int nChar = GetPrivateProfileStringW( wsSec, wsKey, NULL, szBuffW, _MAX_PATH, wsIniFile) ; if ( nChar <= 0) wsVal = _wcsdup( wsDef) ; else { string sVal = LPSTR( WtoAEX<>( szBuffW, CP_ACP)) ; wsVal = _wcsdup( stringtoW( sVal)) ; } return (( wsVal == nullptr) ? FALSE : TRUE) ; } //---------------------------------------------------------------------------- BOOL __stdcall EgtWriteStringUtf8ToIni( const wchar_t* wsSec, const wchar_t* wsKey, const wchar_t* wsVal, const wchar_t* wsIniFile) { // salvo la stringa nel file INI come ANSI/UTF-8 ma scritta in variabile WChar string sVal = wstrztoA( wsVal) ; return WritePrivateProfileStringW( wsSec, wsKey, AtoWEX<>( sVal.data(), CP_ACP), wsIniFile) ; }