Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Write a Byte Order Mark (BOM) to the CSV file. #5

Merged
merged 1 commit into from
Nov 30, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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