Kean Walmsley

July 2009

Sun Mon Tue Wed Thu Fri Sat
      1 2 3 4
5 6 7 8 9 10 11
12 13 14 15 16 17 18
19 20 21 22 23 24 25
26 27 28 29 30 31  

Twitter Updates

    follow me on Twitter



    « Free API webcasts | Main | Linking 2D and 3D with the DWF Viewer 7 API »

    July 14, 2006

    Migrating ObjectARX applications to support Unicode - some resources

    The work we did to migrate AutoCAD 2007 to use Unicode (rather than MBCS), has impacted many developers around the world. For those that are yet to go through the pain themselves, I thought I'd talk about the resources that are available to ObjectARX developers needing to port their applications to Unicode.

    Firstly, you should check out the Migration Guide that ships with the ObjectARX 2007 SDK (docs/acad_xmg.chm):

    Unicode_migration_docs







    There's a whole section called "Upgrading to Unicode", with lots of useful information. A good deal of the material in the guide was compiled during the development phase of AutoCAD 2007, as our own engineering teams got to grips with porting AutoCAD to support Unicode.

    Here's a quick outline listing of the topics, to give you a feel for the contents:

    • Upgrading to Unicode
      • Why Convert AutoCAD to Unicode?
      • Terminology and Basic Concepts
        • Characters and Glyphs
        • MBCS, Multi-byte, DBCS, ANSI, ASCII, and Code Pages
        • Unicode and its Formats (UTF-8, UTF-16, and UTF-32)
        • Compiler Types: char, wchar_t
        • Autodesk Type: ACHAR
        • Affected AutoCAD-based Products
        • Effect of Unicode Conversion on AutoCAD File Types
      • Creating Unicode-compatible Source Code
        • Unicode Porting Tool: Visual Teefy
        • Text File Utilities Provided in the ObjectARX SDK
        • Outline of Autodesk Porting Process
        • Updating Large ObjectARX and ObjectDBX Applications
        • Project Definitions for Unicode Compilation
          • Command Line Processing Tip
        • Basic Coding Tasks
          • Change char to ACHAR or TCHAR for ObjectARX APIs
          • Guidelines for Using TCHAR and ACHAR
          • Wrap Literal Strings and Characters with _T() or ACRX_T()
          • Replace ANSI String Pointer Types
          • Update String Formatting Functions
          • Check String Allocations for TCHAR Compatibility
          • Check Usage of Win32 APIs With No Unicode Equivalents
          • Check Usage of Lead Byte APIs
          • Use _TUCHAR in Unicode Character Classification Functions
          • Use #ifdef to Call the Correct Unicode Function
          • Replace strlen() With _tcslen, Rather Than _tcsclen, in Dual Build Code
          • Use Unicode Code Page Descriptors in Win32 APIs
          • Use Native wchar_t
          • AcArray of std::wstring Type Requires Special Allocator Argument
          • DCL Dialogs Use Unicode, but Definition Files are ANSI
        • Secondary Coding Tasks
          • Centralize Recurring Literal Strings
          • Replace Char Buffers with String Classes
          • Revisit Low-Level Win32 API Calls
          • Avoid Calling CRichEditCtrl::GetSelText()
          • Evaluate Usage of wctombs() And mbstowcs()
        • Prepare User Interface for Unicode Compatibility
          • Fine-Tuning System Font Usage for Special Cases
        • Prepare File I/O for Unicode Compatibility
        • Tips on Supporting Supplementary Plane (UTF-32) Characters
        • Linker Errors Caused By Conflicting Definitions of wchar_t
      • Frequently Asked Questions
      • Resources

    Additionally I'd recommend using a tool called Visual Teefy, which is distributed via the ADN website. The name comes from the fact it helps add the T() macro into string literals (among other things), hence "T()-ify" => Teefy. The tool hooks off the Visual Studio IDE's search & replace mechanism to find potentially problematic pieces of code, and provide suggestions on how to address them. It's not recommended to use the automatic settings (Teefy really just makes suggestions), as clearly a  search & replace-based tool is inevitably going to have trouble - as an example - differentiating a string literal in a compiler directive (such as #include "acdb.h" - which does not need any modification) from a string literal that does require the use of the T() macro.

    As for other resources, I'd recommend searching the ADN KB, if you have access to it, or submitting your questions via the ObjectARX discussion group or DevHelp Online: at this stage it's almost certain that someone in our development community has experienced the same migration issues you're hitting, and it can certainly save time to ask.

    TrackBack

    TrackBack URL for this entry:
    http://www.typepad.com/services/trackback/6a00d83452464869e200d8349fd7c653ef

    Listed below are links to weblogs that reference Migrating ObjectARX applications to support Unicode - some resources:

    Comments

    Hello,

    Why some of the ObjectARX include files contains deprecated CRT functions ?

    ex: acdmmutils.h, asdkpromptbase.h contains ::wcscpy

    Regards
    Zoltán

    Hi Zoltan,

    I think it's a question of timing: for the majority of the AutoCAD 2007 development cycle we were building with VC7.1 - VC8 only showed up quite late in the day (and it's in VC8 that the _s functions were introduced). So I think it's most likely an oversight due to the timing of the Visual Studio release.

    If this impacts your use of the ObjectARX headers, please submit your request via DevHelp Online (as I see you're an ADN member). I'd pass it on myself, but I don't want to encourage the use of this blog as a channel for support.

    Regards,

    Kean

    Dear Kean,

    I was just curious. This isn't affecting my development process.

    Regards,
    Zoltán

    Hi Kean,

    Great blog. Even though I only understand a small amount of your blog, it can only help people like myself learn better techniques in less time. Not to mention that it's about time the guys behind the programs had their say!

    Col.

    Thanks for your support, Col, it's much appreciated.

    Regards,

    Kean

    (1)how to concat two ACHAR strings?

    (2)when I tried to write ACHAR characters in file(created using fstream) junk characters are displayed? how to make files compitable(text file) with ACHAR?

    1. You'll find in AdAChar.h that ACHAR is just a typedef to wchar_t:

    typedef wchar_t ACHAR;

    So you should be able to use wcscat and related string manipulation functions:

    wchar_t *wcscat(
    wchar_t *strDestination,
    const wchar_t *strSource
    );

    I haven't made substantial use of ACHAR myself, though, so there may be a more elegant way to do this.

    2. I have no idea how you're writing the file, and probably wouldn't be able to help if I did: I suggest you post your question to the ObjectARX Discussion Group.

    Kean

    Thanks for reply.

    how to convert ACHAR to Char?

    As mentioned, an ACHAR is just a wchar_t, so I suggest searching MSDN for information on conversion between wchar_t and char.

    Kean

    Hi ,

    Can u suggest me how to call ObjectArx function from AutoLISP Function .

    regards,
    Chandu

    Register the command using acedDefun(), then you can simply call it from LISP (with a little work to marshall the parameters).

    Please direct further off-topic questions to the appropriate discussion group.

    Kean

    Verify your Comment

    Previewing your Comment

    This is only a preview. Your comment has not yet been posted.

    Working...
    Your comment could not be posted. Error type:
    Your comment has been posted. Post another comment

    The letters and numbers you entered did not match the image. Please try again.

    As a final step before posting your comment, enter the letters and numbers you see in the image below. This prevents automated programs from posting comments.

    Having trouble reading this image? View an alternate.

    Working...

    Post a comment

    Feed & Share

    Search