Thread: Converting unicode filenames to ANSI

  1. #1
    Registered User
    Join Date
    Jul 2010
    Posts
    2

    Unhappy Converting unicode filenames to ANSI

    Would like to find a convenient way to convert a unicode filename to ansi -

    Have a project that needs to be able to recognize and open files with foreign chars in the fileame.

    It could be compiled in unicode to make use of the unicode versions of the file routines, but doing so creates a problem with the document converter.

    GetOpenFileName() replaces the chars that it can't represent as '?' chars and so the original filename is lost, so programmatically renaming or creating a temp copy with an ANSI name seems to be out of the question.

    So, is there a means to do this without recompiling as unicode?

    thanks

  2. #2
    Registered User Codeplug's Avatar
    Join Date
    Mar 2003
    Posts
    4,981
    Just use the wide API's. You don't have change any compiler setting for that.

    WINCOMMDLGAPI BOOL APIENTRY GetOpenFileNameA(LPOPENFILENAMEA);
    WINCOMMDLGAPI BOOL APIENTRY GetOpenFileNameW(LPOPENFILENAMEW);
    #ifdef UNICODE
    #define GetOpenFileName GetOpenFileNameW
    #else
    #define GetOpenFileName GetOpenFileNameA
    #endif // !UNICODE
    Just use the "W" versions.

    gg

  3. #3
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    Quote Originally Posted by CaptainKirk View Post
    GetOpenFileName() replaces the chars that it can't represent as '?' chars and so the original filename is lost, so programmatically renaming or creating a temp copy with an ANSI name seems to be out of the question.
    How do you think convert it would change that fact? It most certainly will not.
    Unicode can represent a far wider amount of characters than ANSI. Convert it to ANSI would just insert more "?" into it anyway.
    Just use Wide APIs as Codeplug mentioned.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  4. #4
    Registered User
    Join Date
    Jul 2010
    Posts
    2
    I'm aware of the wide versions - the development scheme here is that these things have been wrappered for the sake of cross-platform development and I have no permissions to change the library....

    I was hoping there was another way around this, but maybe I can convince the powers that be that mods are needed in the lib....

    thanks all...

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. ISAPI unicode filenames
    By Mackan2009 in forum C++ Programming
    Replies: 15
    Last Post: 11-30-2009, 12:20 AM
  2. Dealing with Unicode and ANSI - Templates
    By Tonto in forum C++ Programming
    Replies: 9
    Last Post: 06-15-2007, 03:57 PM
  3. Unicode v ANSI Calls
    By Davros in forum Windows Programming
    Replies: 3
    Last Post: 04-18-2006, 09:35 AM
  4. Replies: 5
    Last Post: 10-09-2002, 12:37 PM
  5. UNICODE and GET_STATE
    By Registered in forum C++ Programming
    Replies: 1
    Last Post: 07-15-2002, 03:23 PM

Tags for this Thread