Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. Unicode prob?

Unicode prob?

Scheduled Pinned Locked Moved C / C++ / MFC
helpc++designquestion
5 Posts 4 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Offline
    S Offline
    Software_Specialist
    wrote on last edited by
    #1

    Hi all well i have a lil problem here I have created few classes and stuff and i have used normal char type variable. Now when i am writing code for UI, i have to use function strlen, strcpy , strcmp... For instance if i do... char str[10]; CString Password; strcpy(str, Password); In above code i get error saying can not convert parameter 2 from 'CString to const char*' So to overcome this problem i made these changes as shown below... wchar_t str[10]; CString Password; wcscpy(str, Password); This solved my error but now i have many other errors. where i used char . So now do i have to change the whole application where i have used char. All the functions and stuff.. Is it now compulsory to use unicode in MFC....??? I am new to MFC so new to Unicode thingy..bit confusing though.. Can any one shed some light over this.. Any or all help would be greatly appreciated.. Thanks a lot

    S M R 3 Replies Last reply
    0
    • S Software_Specialist

      Hi all well i have a lil problem here I have created few classes and stuff and i have used normal char type variable. Now when i am writing code for UI, i have to use function strlen, strcpy , strcmp... For instance if i do... char str[10]; CString Password; strcpy(str, Password); In above code i get error saying can not convert parameter 2 from 'CString to const char*' So to overcome this problem i made these changes as shown below... wchar_t str[10]; CString Password; wcscpy(str, Password); This solved my error but now i have many other errors. where i used char . So now do i have to change the whole application where i have used char. All the functions and stuff.. Is it now compulsory to use unicode in MFC....??? I am new to MFC so new to Unicode thingy..bit confusing though.. Can any one shed some light over this.. Any or all help would be greatly appreciated.. Thanks a lot

      S Offline
      S Offline
      SandipG
      wrote on last edited by
      #2

      if you define _UNICODE you have to follow unicode. For CString to const char* error you could have used some macro for typecasting. no need to go for WCHAR. There are many other ways to e.g. password.GetBuffer(Password.GetLength()); which will return yoi char *.

      S 1 Reply Last reply
      0
      • S Software_Specialist

        Hi all well i have a lil problem here I have created few classes and stuff and i have used normal char type variable. Now when i am writing code for UI, i have to use function strlen, strcpy , strcmp... For instance if i do... char str[10]; CString Password; strcpy(str, Password); In above code i get error saying can not convert parameter 2 from 'CString to const char*' So to overcome this problem i made these changes as shown below... wchar_t str[10]; CString Password; wcscpy(str, Password); This solved my error but now i have many other errors. where i used char . So now do i have to change the whole application where i have used char. All the functions and stuff.. Is it now compulsory to use unicode in MFC....??? I am new to MFC so new to Unicode thingy..bit confusing though.. Can any one shed some light over this.. Any or all help would be greatly appreciated.. Thanks a lot

        M Offline
        M Offline
        Matthew Faithfull
        wrote on last edited by
        #3

        It's not compulsory to use Unicode, you can remove the /D UNICODE from the MSVC project settings, but it is generally a good idea to go Unicode these days. The short answer to whether you are going to have to change all the code or not is YES and the sooner you do it the less painful it will be:(. One option is to change your strcpys for tcscpys etc so that the code will compile with and without UNICODE defined. This way you can do the transition more gradually and in the meanwhile non Unicode builds which mix TCHARs with chars will work, keep putting in the changes to TCHAR functions until the code also builds and works in UNICODE. TCHAR and tcs functions turn into wchar and wcs with UNICODE defined(remeber to define _UINICODE as well beacuse someone at Microsoft screwed up) and they turn back into ordinary char stuff in non Unicode builds. You'll need <tchar.h> included of course. Welcome to the wonderful world of international software :-D

        Nothing is exactly what it seems but everything with seems can be unpicked.

        1 Reply Last reply
        0
        • S Software_Specialist

          Hi all well i have a lil problem here I have created few classes and stuff and i have used normal char type variable. Now when i am writing code for UI, i have to use function strlen, strcpy , strcmp... For instance if i do... char str[10]; CString Password; strcpy(str, Password); In above code i get error saying can not convert parameter 2 from 'CString to const char*' So to overcome this problem i made these changes as shown below... wchar_t str[10]; CString Password; wcscpy(str, Password); This solved my error but now i have many other errors. where i used char . So now do i have to change the whole application where i have used char. All the functions and stuff.. Is it now compulsory to use unicode in MFC....??? I am new to MFC so new to Unicode thingy..bit confusing though.. Can any one shed some light over this.. Any or all help would be greatly appreciated.. Thanks a lot

          R Offline
          R Offline
          Rajkumar R
          wrote on last edited by
          #4

          Hi, Always uses TCHAR instead of char / wchat_t and the generic-text functions defined in Tchar.h. This will maps appropriately if used _UNICODE or not.

          1 Reply Last reply
          0
          • S SandipG

            if you define _UNICODE you have to follow unicode. For CString to const char* error you could have used some macro for typecasting. no need to go for WCHAR. There are many other ways to e.g. password.GetBuffer(Password.GetLength()); which will return yoi char *.

            S Offline
            S Offline
            Software_Specialist
            wrote on last edited by
            #5

            oh i wasn't aware of this.I already started changing stuff and error seems to be never ending. Hmm i got a backup of project though... So i guess i need to start it again. Well i have not define _UNICODE...and what could be solution you could think of in the problem i mentioned. Can we still use unicode without defining _UNICODE. I guess we can cos few things are working when i changed to wchar_t and i have not defined _UNICODE anywhere... Thanks

            1 Reply Last reply
            0
            Reply
            • Reply as topic
            Log in to reply
            • Oldest to Newest
            • Newest to Oldest
            • Most Votes


            • Login

            • Don't have an account? Register

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • World
            • Users
            • Groups