Skip to content

Commit 8a28795

Browse files
committedAug 18, 2023
[#75] Migration to YAHEL hexa-editor (Part 15: Unicode support)
1 parent 2cdac90 commit 8a28795

File tree

3 files changed

+13
-12
lines changed

3 files changed

+13
-12
lines changed
 

‎Main/Main.vcxproj

+2
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,7 @@
101101
<PreprocessorDefinitions>WIN32;_CRT_SECURE_NO_WARNINGS;_DEBUG;_WINDOWS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
102102
<RuntimeLibrary>MultiThreadedDLL</RuntimeLibrary>
103103
<DisableSpecificWarnings>4482</DisableSpecificWarnings>
104+
<TreatWChar_tAsBuiltInType>false</TreatWChar_tAsBuiltInType>
104105
</ClCompile>
105106
<Link>
106107
<SubSystem>Windows</SubSystem>
@@ -177,6 +178,7 @@
177178
<CallingConvention>StdCall</CallingConvention>
178179
<FloatingPointExceptions>false</FloatingPointExceptions>
179180
<DisableSpecificWarnings>4482</DisableSpecificWarnings>
181+
<TreatWChar_tAsBuiltInType>false</TreatWChar_tAsBuiltInType>
180182
</ClCompile>
181183
<Link>
182184
<SubSystem>Windows</SubSystem>

‎Main/src/HexaEditor.cpp

+9-12
Original file line numberDiff line numberDiff line change
@@ -412,22 +412,19 @@ using namespace Yahel;
412412
}
413413

414414
static bool DoPromptSingleTypeFileName(PWCHAR lpszFileNameBuffer,WORD bufferCapacity,LPCWSTR singleFilter,DWORD flags){
415+
const CString fileName=Utils::DoPromptSingleTypeFileName(
416+
lpszFileNameBuffer&&*lpszFileNameBuffer ? (LPCTSTR)Utils::ToStringT(lpszFileNameBuffer) : nullptr,
417+
singleFilter&&*singleFilter ? (LPCTSTR)Utils::ToStringT(singleFilter) : nullptr,
418+
flags
419+
);
420+
if (fileName.IsEmpty())
421+
return false;
415422
#ifdef UNICODE
416-
static_assert(false,"");
423+
::lstrcpyn( lpszFileNameBuffer, fileName, bufferCapacity );
417424
#else
418-
char singleFilterA[80], lpszFileNameBufferA[MAX_PATH];
419-
::WideCharToMultiByte( CP_ACP, 0, singleFilter,-1, singleFilterA,ARRAYSIZE(singleFilterA), nullptr,nullptr );
420-
::WideCharToMultiByte( CP_ACP, 0, lpszFileNameBuffer,-1, lpszFileNameBufferA,ARRAYSIZE(lpszFileNameBufferA), nullptr,nullptr );
421-
const CString fileName=Utils::DoPromptSingleTypeFileName(
422-
lpszFileNameBuffer&&*lpszFileNameBuffer ? lpszFileNameBufferA : nullptr,
423-
singleFilter&&*singleFilter ? singleFilterA : nullptr,
424-
flags
425-
);
426-
if (fileName.IsEmpty())
427-
return false;
428425
::MultiByteToWideChar( CP_ACP,0, fileName,-1, lpszFileNameBuffer,bufferCapacity );
429-
return true;
430426
#endif
427+
return true;
431428
}
432429

433430
bool CHexaEditor::ShowOpenFileDialog(LPCWSTR singleFilter,DWORD ofnFlags,PWCHAR lpszFileNameBuffer,WORD bufferCapacity) const{

‎Main/src/Utils.h

+2
Original file line numberDiff line numberDiff line change
@@ -495,9 +495,11 @@ namespace Utils{
495495
#ifdef UNICODE
496496
LPCSTR ToStringA(LPCWSTR s);
497497
inline CString ToStringT(LPCSTR s){ return s; }
498+
inline LPCTSTR ToStringT(LPCWSTR s){ return s; }
498499
#else
499500
inline LPCSTR ToStringA(LPCSTR s){ return s; }
500501
inline LPCTSTR ToStringT(LPCSTR s){ return s; }
502+
inline CString ToStringT(LPCWSTR s){ return s; }
501503
#endif
502504
CString SimpleFormat(LPCTSTR format,LPCTSTR param);
503505
CString SimpleFormat(LPCTSTR format,LPCTSTR param1,LPCTSTR param2);

0 commit comments

Comments
 (0)
Please sign in to comment.