Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6339747
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T19:42:18+00:00 2026-05-24T19:42:18+00:00

I use a self-made error/log-class for my project which is also be able to

  • 0

I use a self-made error/log-class for my project which is also be able to store/load itself into/from a file. To make it easier for me when handling more objects I want to pass a file stream by-reference to this function which then uses the write/read member of the stream.

Save with:

in.open(L"XError.err",std::ios::in | std::ios::out | std::ios::binary | std::ios::trunc);

Load with:

in.open(L"XError.err",std::ios::in | std::ios::out | std::ios::binary);

For saving:

unsigned int HError::SaveToBufferW(std::wfstream& file)
{
    _ErrorSaveStruct ess = {0};
    ESS.IsUNICODE = true;
    ESS.ItemCount = 9999999;
    file.write((wchar_t*)&ess,sizeof(_ErrorSaveStruct) / sizeof(wchar_t));
    return 0;
}

For loading:

int HError::LoadFromBufferW(std::wfstream& file)
{
    _ErrorSaveStruct ess = {0};
    file.read((wchar_t*)&ess,sizeof(_ErrorSaveStruct) / sizeof(wchar_t));
    return 0;
}

I checked the file and found out that nothing but whitespaces is written.
When I read/write a Unicode-string everything works and the string as well is readable in the file.

Edit: here you go

 struct _ErrorSaveStruct
{
    unsigned int MsgSize;
    unsigned int TimeSize;
    unsigned int LastErrorSize;
    int ItemCount;
    int errState;
    bool InitMsg;
    bool IsUNICODE;
};
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-24T19:42:19+00:00Added an answer on May 24, 2026 at 7:42 pm

    ok, used another answer to bypass my problem in some way:

    int main()
    {   
    HLib::_ErrorSaveStruct Ess = {0};  // just a namespace
    Ess.IsUNICODE = true;
    Ess.errState = 100;
    Ess.ItemCount = 9999;
    
    wchar_t* StringTest[1] = {L"WOORD"};    // same like (wchar_t[5])
    
    FILE* iobuf = NULL;
    
    // create new in binary read-write mode
    if (_wfopen_s(&iobuf,L"WTest.err",L"wb+")==0) 
    {
            //WRITING BLOCK
        if (fwrite(&Ess,sizeof(Ess),1,iobuf) != 1)  // sizeof_ErrorSaveStruct
            std::cout << "Fail (Reading struct)";
    
        if (fwrite(StringTest,sizeof(wchar_t) * 5,1,iobuf) != 1) // size = 5 
            std::cout << "Fail (Reading string)";
    
        // reset content
        SecureZeroMemory(&Ess,sizeof(Ess));
        SecureZeroMemory(StringTest,sizeof(wchar_t)*5);
    
        fseek(iobuf,0,0); // rewind
        fflush(iobuf);    // flush because you switch from write to read
    
         /// READING BLOCK
        if (fread(&Ess,sizeof(Ess),1,iobuf) != 1)   // sizeof_ErrorSaveStruct
            std::cout << "Fail (Reading struct)";
    
        if (fread(StringTest,sizeof(wchar_t) * 5,1,iobuf) != 1) // size = 5 
            std::cout << "Fail (Reading string)";
        fclose(iobuf);
    }
    
    return 0;
    

    I really learned something about streams and file IO. Thinking of other solutions, i also could have passed single parameters (int,bool) to wfstream instead of a whole struct. It would have been possible as well to use std::fstream with binary flag set and pass a wchar_t string via write(). Anyway, this solution works well enough for me and I’m really happy about that.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Trying to use this method (gist of which is use self.method_name in the FunnyHelper
we use a self-written 32bit C++ DLL from our C# applications. Now we've noticed
I'm trying to activate a self-made wordpress plugin but am getting a T_Variable error
Is it possible to use Django (and self-made) view decorators with Piston handler methods?
Here's a template I made. I believe it is self-explanatory template <class N, class
I'm trying use self-signed certificate (c#): X509Certificate2 cert = new X509Certificate2( Server.MapPath(~/App_Data/myhost.pfx), pass); on
How secure is it to use self-signed certificates? As far as I understand it,
I'm trying to understand when to use self.method_name vs. when to use Classname.method_name. In
Is there any real use for self modifying code ? I know that they
I have noticed that most Objective-C coders never use the self->ivar syntax when accessing

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.