fwrite failing with japanese language

This is a discussion on fwrite failing with japanese language within the C++ Programming forums, part of the General Programming Boards category; Hi I'm trying to write a binary file (PSD) and have japanese language turned on on my computer right now. ...

  1. #1
    Registered User
    Join Date
    Oct 2007
    Posts
    158

    fwrite failing with japanese language

    Hi I'm trying to write a binary file (PSD) and have japanese language turned on on my computer right now. The program crashes when using fwrite, I think it has to do with that the system is using doublebyte characters. Things works fine when the system is set to another language like swedish. I hope you can help.

    This is the function that crashes, during fwrite:
    Code:
    bool PSDFile::writeSignedInt(int valueToWrite)
    {
        size_t ret = fwrite(&valueToWrite,1,4,m_fd);
        if (ret==4)
            return true;
        return false;
    }
    Do you know why?
    Do I need to check if the system is using doublebyte characters? How do I do that?
    Do I need to adjust things regarding the arguments passed to fwrite?

    Note that I'm not actually writing japanese letters at this point although I will need to do that as well, but it crashes here from just writing any characters it seems.

    Thanks.
    home = hat.position;

  2. #2
    Registered User
    Join Date
    Dec 2006
    Location
    Canada
    Posts
    3,167
    It looks like you are writing an int? What does it have to do with language?

    Did you check m_fd?

  3. #3
    Registered User
    Join Date
    Oct 2007
    Posts
    158
    It seem that the problem could be occuring earlier in the code when the file is created, related to the file name in japanese. I'll be back after some checking.
    home = hat.position;

  4. #4
    Registered User
    Join Date
    Oct 2007
    Posts
    158
    cyberfish, the m_fd pointer was indeed NULL. Should have checked that...

    Anyway, the file creation itself is failing when using japanese characters when I have the system set to use japanese language. I can still use regular characters with the system set like that and it will work. This is what I do when creating the file, perhaps some of you are familiar with this and what needs to be done when using japanese (double byte) characters?
    Code:
    PSDFile* PSDOpen(const char *utf8Name)
    {
        PSDFile* psdFile = new PSDFile;
        if (!psdFile) return NULL;
    
        wchar_t wsName[MAX_PATH];
        MultiByteToWideChar(CP_UTF8, 0, utf8Name, -1, wsName, MAX_PATH );
        psdFile->m_fd = _wfopen(wsName,L"w+b");
    
        return psdFile;
    }
    The functions used here seems to be standard Windows funtionality. Btw, I did not write this myself to start with so I'm not sure what the MultiByteToWideChar function is suppose to do.
    Last edited by DrSnuggles; 06-17-2010 at 09:50 PM.
    home = hat.position;

  5. #5
    Registered User Codeplug's Avatar
    Join Date
    Mar 2003
    Posts
    4,646
    Add error checking and report the resulting error codes.

    Are you sure utf8Name is actually UTF8 encoded?

    gg

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Assembly language.
    By JOZZY& Wakko in forum Tech Board
    Replies: 0
    Last Post: 12-18-2009, 04:58 AM
  2. What's wrong with C++ as a first language?
    By Angie in forum C++ Programming
    Replies: 43
    Last Post: 09-20-2009, 10:39 PM
  3. Replies: 15
    Last Post: 08-09-2009, 11:20 AM
  4. Japanese
    By IcyDeath in forum A Brief History of Cprogramming.com
    Replies: 27
    Last Post: 12-03-2001, 05:36 PM
  5. Visual J#
    By mfc2themax in forum A Brief History of Cprogramming.com
    Replies: 0
    Last Post: 10-08-2001, 02:41 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21