0

I try to read a file via MFC:

CString string;
CStdioFileEx gameFile;
bool have_file = false;
if (PathFileExists(filePathsAndNames[i].first + L"\\main.lua"))
{
    gameFile.Open(filePathsAndNames[i].first + L"\\main.lua", CFile::modeRead);
    have_file = true;
}
else if (PathFileExists(filePathsAndNames[i].first + L"\\main3.lua"))
{
    gameFile.Open(filePathsAndNames[i].first + L"\\main3.lua", CFile::modeRead);
    have_file = true;
}
if (have_file)
{
    gameFile.SetCodePage(CP_UTF8);
    CString game_name;
    CString game_name_en;
    CString game_author;
    CString game_version;
    const int MAX_STR_CNT = 5; //не больше этого количества строк от начала
    int curr_str = 0;
    while (gameFile.ReadString(string)) {
        ...
    }
}

When a file has UTF-8 encoding without a BOM, the readString() method skips near two, three characters in the first line. When the file has UTF-8 encoding with a BOM, all is ok.

How can I fix it?

Is it an issue which I should report to Microsoft? If yes, how can I do it?

Remy Lebeau
  • 555,201
  • 31
  • 458
  • 770
  • 1
    If you're using a `CStdioFileEx` you are requesting that the CRT perform translation for you. If you're using non-standard processing (UTF-8 *is* non-standard), you're going to have to set up the environment properly. It's probably a lot easier to not have the system do any processing, and just read the actual binary contents of the file instead. – IInspectable Dec 31 '22 at 15:25
  • @IInspectable But why i can set utf8 encoding without any problem and how i can fix problem? As i understand,for binary mode i should manually convert chars to utf8 without bom. And Why for utf8 with bom all ok? Maybe exists more best class for reading utf8 lines from file,instead of CStdioFileEx? – alexandr kozlovskiy Dec 31 '22 at 15:52
  • May be someone know,how report issue to microsoft about it? – alexandr kozlovskiy Dec 31 '22 at 20:21
  • Why do you want to report this issue to Microsoft? You should contact the author of the `CStdioFileEx` class instead to get an answer why they decided to implement their class the way they have. Or to get documentation for a start. – IInspectable Dec 31 '22 at 21:04
  • @IInspectable Because author of this class microsoft.... If you know human from microsoft team,who created this class,cammunicate to me with him. As for me,i don't know his contact,so i ask,how to report issue directly to microsoft. May be you knoe,how i can do it? – alexandr kozlovskiy Jan 01 '23 at 00:55
  • `CStdioFileEx` isn't part of MFC. As such, Microsoft won't care nor fix your issue. You will have to find out who wrote the code you're using. – IInspectable Jan 01 '23 at 09:00
  • @IInspectable,it class from microsoft,even if it not use mfc. – alexandr kozlovskiy Jan 01 '23 at 15:48
  • 1
    You've got that backwards. `CStdioFileEx` *is* using MFC, but isn't authored, published, nor supported by Microsoft. You'll find the actual author [here](https://www.codeproject.com/Articles/4119/CStdioFile-derived-class-for-multibyte-and-Unicode). – IInspectable Jan 01 '23 at 15:55
  • @IInspectable,but what do you think about fact,what we have documentation from microsoft? (https://learn.microsoft.com/cpp/mfc/reference/cstdiofile-class). – alexandr kozlovskiy Jan 01 '23 at 18:20
  • So,how i can report issue to microsoft? – alexandr kozlovskiy Jan 01 '23 at 19:58
  • 1
    I use this class in all my projects: https://www.codeproject.com/Articles/7958/CTextFileDocument. It makes serializing to UTF8 and other encodings quite easy IMHO. – Andrew Truckle Jan 01 '23 at 19:59
  • 1
    `CStdioFile` is part of MFC. `CStdioFileEx` is not part of MFC. You're having an issue with `CStdioFileEx`, so Microsoft doesn't need to know, nor care. I have linked you to the author of `CStdioFileEx` [previously](https://stackoverflow.com/questions/74970432/how-to-set-utf8-encoding-without-bom-for-cstdiofileex-c#comment132309450_74970432). That's the person you need to get in touch with. – IInspectable Jan 01 '23 at 20:12
  • @IInspectable Yes,you right. It class not from microsoft and i wrote to author of this class. – alexandr kozlovskiy Jan 04 '23 at 20:09

0 Answers0