[RESOLVED] Unicode and ASSERT
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 9 of 9

Thread: [RESOLVED] Unicode and ASSERT

  1. #1
    Join Date
    Mar 2004
    Posts
    119

    [RESOLVED] Unicode and ASSERT

    I have a huge program that started it's life 15 years ago as a VS6 project under Windows 9.x. It's always been a multi-byte program. We've decided to finally convert to unicode and I'm attempting the task now. However I'm running into a weird issue. When I switch to the unicode config I get errors everywhere we use ASSERT....

    Error C2664 'BOOL AfxAssertFailedLine(LPCSTR,int)': cannot convert argument 1 from 'TCHAR [89]' to 'LPCSTR'

    If I start a brand new MFC project and use ASSERT it works fine, so I assume it's some sort of project/solution configuration thing but I'm not sure where to even look. These projects have been upgraded through at least 5 versions of VS, and there are probably close to 100 projects in the solution.

    Has anyone ever run into this issue before? Any clue how to fix it?

  2. #2
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Wallisellen (ZH), Switzerland
    Posts
    18,969

    Re: Unicode and ASSERT

    Could you look at the dependency? Perhaps, the old mfc42 is still involved?
    Victor Nijegorodov

  3. #3
    Join Date
    Mar 2004
    Posts
    119

    Re: Unicode and ASSERT

    I'm not explicitly linking to MFC anywhere if that's what you mean. I'm just using the MFC as a shared DLL option on the general page.

  4. #4
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Wallisellen (ZH), Switzerland
    Posts
    18,969

    Re: Unicode and ASSERT

    Quote Originally Posted by Dan203 View Post
    I'm not explicitly linking to MFC anywhere if that's what you mean. I'm just using the MFC as a shared DLL option on the general page.
    Well, I understand it.
    Just meant that (after the the moving to the next versions of VS and to UNICODE) there could stayed some dependencies on the old MFC libraries supporting ANSI rather than UNICODE.
    Try to use the Dependency Walker (depends.exe) to investigate it.
    Victor Nijegorodov

  5. #5
    Join Date
    Mar 2004
    Posts
    119

    Re: Unicode and ASSERT

    I can't even get the code to compile so not sure how I could use depends.

    I'm having other strange issues too. There are a bunch of places where calling new is also throwing a compile error. Could that be related?

    I can flip back to the multi-byte config and the code all compiles just fine.

  6. #6
    2kaud's Avatar
    2kaud is offline Super Moderator Power Poster
    Join Date
    Dec 2012
    Location
    England
    Posts
    5,787

    Re: Unicode and ASSERT

    Yes, its all related. Anywhere you use a char, or char* (eg LPSTR, LPCSTR etc) all potentially have to be changed. Anywhere you use a literal string (eg "qwerty") potentially has to be changed (eg L"qwerty") etc etc etc. STL string class becomes wstring, cout becomes wcout etc. char becomes wchar_t, LPSTR becomes LPWSTR. LPTSTR automatically adjusts properly for unicode/multi-byte so does TCHAR. All the str???() functions may need to be changed (eg strcpy() becomes wcscpy() etc) and...
    All advice is offered in good faith only. You are ultimately responsible for the effects of your programs and the integrity of the machines they run on. Anything I post, code snippets, advice, etc is licensed as Public Domain https://creativecommons.org/publicdomain/zero/1.0/

    C++17 Compiler: Microsoft VS2017 (15.4.1)

  7. #7
    Join Date
    Mar 2004
    Posts
    119

    Re: Unicode and ASSERT

    I'm doing that. I just can't understand why a simple ASSERT like...

    ASSERT(pObject)

    is failing.

    In fact it looks like every single ASSERT in the whole program is failing.


    Edit:
    I just tried adding...

    ASSERT(false);

    to the main dialog class and it gets the squiggly red line under it too.

  8. #8
    Join Date
    Mar 2004
    Posts
    119

    Re: Unicode and ASSERT

    I figured it out. I had used this automated program that goes through the code and replaces plain strings with _T() and replaces char with TCHAR, etc.... A bunch of the files had a section like this...

    #ifdef _DEBUG
    #undef THIS_FILE
    static char THIS_FILE[] = __FILE__;
    #define new DEBUG_NEW
    #endif

    and it had replaced them with...

    #ifdef _DEBUG
    #undef THIS_FILE
    static TCHAR THIS_FILE[] = _T(__FILE__);
    #define new DEBUG_NEW
    #endif

    which was screwing up ASSERT and new.

  9. #9
    Join Date
    Jun 2003
    Location
    Armenia, Yerevan
    Posts
    696

    Re: [RESOLVED] Unicode and ASSERT

    Bingo. I was going to express the same idea, but finally the issue resolved without a guru's intervention.

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

This a Codeguru.com survey!


On-Demand Webinars (sponsored)