Thread: CString problem

  1. #1
    Registered User
    Join Date
    Oct 2006
    Posts
    5

    CString problem

    Hi!
    I am working with CString and i got a ptoblem with it.

    I declared an array of strings:

    Code:
    char *Regs16[10]={"ax","bx","cx","dx","bp","sp","di","si","cs","ds"};
    
    
    //then I declared:
    
         CString TempStr = ListLines[NumLines-1].Operand;
    
            int NIndexComma=TempStr.Find(',');
    
            CString TempLeft=TempStr.Left(NIndexComma);
    
            CString TempRight=TempStr.Right(NIndexComma);
    
    //Then I started comparisions like this:
    
    if (TempLeft.CompareNoCase(Regs16[i])
    This results in an error ::

    Error 8 error C2664: 'ATL::CStringT<BaseType,StringTraits>::CompareNoCa se' : cannot convert parameter 1 from 'char *' to 'const wchar_t *' c:jayasm\jayasm.cpp 123.

    What is this error and how can I handle it? I am working on 2005visual studio.
    I tried putting a _T and also tried putting an L before the Reg16[i] variable.
    But did not work.

    Thankyou.

  2. #2
    Registered User
    Join Date
    Jan 2005
    Posts
    7,364
    You are building your project with UNICODE defined, so your CString is a wide character based CString. If you did that on purpose, change your array to wchar_t* instead of char* (actually, it should be const wchar_t* or const char*). If you don't want unicode, then change your project settings.

  3. #3
    Hurry Slowly vart's Avatar
    Join Date
    Oct 2006
    Location
    Rishon LeZion, Israel
    Posts
    6,794
    Actually in the MSVC you have macros that provide a way to write a code that will compile both with UNICODE and without it...

    Something like that
    Code:
    const TCHAR *Regs16[10]={_T("ax"),_T("bx")};
    Note - that both the type AND the string should be changed
    All problems in computer science can be solved by another level of indirection,
    except for the problem of too many layers of indirection.
    David J. Wheeler

  4. #4
    Registered User
    Join Date
    Oct 2006
    Posts
    5
    Thank you.I changed the properties and it works now.I also tried changing the
    way I declared.it is finally working.
    Thanks again.

  5. #5
    Reverse Engineer maxorator's Avatar
    Join Date
    Aug 2005
    Location
    Estonia
    Posts
    2,318
    Windows specific.
    "The Internet treats censorship as damage and routes around it." - John Gilmore

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. WS_POPUP, continuation of old problem
    By blurrymadness in forum Windows Programming
    Replies: 1
    Last Post: 04-20-2007, 06:54 PM
  2. weird CString problem
    By axr0284 in forum Windows Programming
    Replies: 1
    Last Post: 03-18-2006, 04:05 PM
  3. Laptop Problem
    By Boomba in forum Tech Board
    Replies: 1
    Last Post: 03-07-2006, 06:24 PM
  4. Replies: 5
    Last Post: 11-07-2005, 11:34 PM
  5. half ADT (nested struct) problem...
    By CyC|OpS in forum C Programming
    Replies: 1
    Last Post: 10-26-2002, 08:37 AM