dcsimg
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 5 of 5

Thread: VC++6.0, Unicode, and ANSI strings

  1. #1
    Join Date
    Sep 2012
    Posts
    25

    VC++6.0, Unicode, and ANSI strings

    I have a VC++ 6.0 project that I'm thinking about rebuilding in Unicode. The bigget problem is that the data that I have to processes is 8-bit binary data that sometimes contains strings (e.g. "-12345X") that I have to detect.

    I would like to have a class, something like an equivalent CStringA, that I can use on the 8-bit data when compiled with UNICODE/_UNICODE defined. I don't want to reinvent the wheel if someone has already done the heavy lifting. If not then I was thinking of wrapping the string function (i.e. strcat(), strcmp(), strcpy(), etc.) in a class.

    Actually, I'm not sure it is worth the effort to rebuild in Unicode.

    Anybody know of something I can beg, borrow, or steal?

  2. #2
    Join Date
    Nov 2000
    Location
    Voronezh, Russia
    Posts
    6,602

    Re: VC++6.0, Unicode, and ANSI strings

    In case it works in ANSI for you, why bother to rebuild? Rebuild may make sense when you wish to move to a contemporary compiler, or multi-cultural /lingual support is required. If none of those is the case, why bother to rebuild?

    Besides, having a project set up for Unicode by no means implies your strings cannot be ANSI when required. You can combine those wherever you want alright.
    Best regards,
    Igor

  3. #3
    Join Date
    Sep 2012
    Posts
    25

    Re: VC++6.0, Unicode, and ANSI strings

    Hi Igor,

    I should have provided more information in my original post. In fact, my thoughts were, and are, about moving to a new compiler AND supporting multi-language. Although, at this time, I have no idea what multi-language support entails - I'll worry about that later.

    The problem is that CStrings are ANSI or Unicode depending whether UNICODE/_UNICODE are defined. So I'm left with the problem needing ANSI strings for the data and using Unicode CStrings everywhere else.

    I just don't want to create my own wrapper-class if something already exists that I can use.

    Thanks,
    Mike

  4. #4
    Arjay's Avatar
    Arjay is offline Moderator / EX MS MVP Power Poster
    Join Date
    Aug 2004
    Posts
    13,176

    Re: VC++6.0, Unicode, and ANSI strings

    Here's what I would recommend:

    Compile your program for UNICODE
    All strings and string related api calls are in Unicode (and data passed within your program is Unicode)
    Convert data that needs to be ansi when it enters and leaves your program
    Provide a conversion layer so the conversions get done in one place (makes it easier to debug)
    Make use of the ATL/MFC String Conversion Macros

  5. #5
    Join Date
    Nov 2000
    Location
    Voronezh, Russia
    Posts
    6,602

    Re: VC++6.0, Unicode, and ANSI strings

    You keep talking about CString while there is no such a class. There are CStringA and CStringW. Unicode-aware macros do you a favor and translate CString to CStringW, but for strict ANSI data you always can use CStringA specifying the one explicitly. I still don't get what sort of "your own wrapper class" you would need other than standard string classes.
    Best regards,
    Igor

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Windows Mobile Development Center


Click Here to Expand Forum to Full Width




On-Demand Webinars (sponsored)