Skip to content

Commit

Permalink
Merge pull request #5 from enlyze/feature/utf8-bom-csv
Browse files Browse the repository at this point in the history
Write a Byte Order Mark (BOM) to the CSV file.
  • Loading branch information
ColinFinck authored Nov 30, 2023
2 parents 82a215b + 76aa4b7 commit 7d71f2c
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
11 changes: 9 additions & 2 deletions src/csv_exporter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,11 +60,18 @@ ExportCSV(const std::wstring& wstrCSVFilePath, const std::vector<S7DeviceSymbolI
return CS7PError(L"CreateFileW failed with error " + std::to_wstring(GetLastError()));
}

// Write the CSV output.
// Write the BOM to indicate UTF-8 output.
const unsigned char ByteOrderMark[] = { 0xEF, 0xBB, 0xBF };
DWORD cbWritten;
if (!WriteFile(hFile.get(), ByteOrderMark, sizeof(ByteOrderMark), &cbWritten, nullptr))
{
return CS7PError(L"WriteFile failed for the ByteOrderMark with error " + std::to_wstring(GetLastError()));
}

// Write the CSV output.
if (!WriteFile(hFile.get(), strCSV.c_str(), strCSV.size(), &cbWritten, nullptr))
{
return CS7PError(L"WriteFile failed with error " + std::to_wstring(GetLastError()));
return CS7PError(L"WriteFile failed for the CSV content with error " + std::to_wstring(GetLastError()));
}

return std::monostate();
Expand Down
2 changes: 1 addition & 1 deletion src/version.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
#pragma once

#define APP_MAJOR_VERSION 2
#define APP_MINOR_VERSION 3
#define APP_MINOR_VERSION 4


// The following macro magic turns arbitrary preprocessor constants into strings.
Expand Down

0 comments on commit 7d71f2c

Please sign in to comment.