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. MessageBoxW and converting to LPCWSTR

MessageBoxW and converting to LPCWSTR

Scheduled Pinned Locked Moved C / C++ / MFC
helpvisual-studio
9 Posts 6 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
    sawerr
    wrote on last edited by
    #1

    Hi MessageBox(NULL, "Hello World", "Message Box Title -- Hello World", MB_OK); Error: error C2664: 'MessageBoxW' : cannot convert parameter 2 from 'const char [12]' to 'LPCWSTR' IDE:VS2005 I don't understand why it gives this error. Can you please tell me what the problem is and how i can solve it. Thanks

    U F 2 Replies Last reply
    0
    • S sawerr

      Hi MessageBox(NULL, "Hello World", "Message Box Title -- Hello World", MB_OK); Error: error C2664: 'MessageBoxW' : cannot convert parameter 2 from 'const char [12]' to 'LPCWSTR' IDE:VS2005 I don't understand why it gives this error. Can you please tell me what the problem is and how i can solve it. Thanks

      U Offline
      U Offline
      uday kiran janaswamy
      wrote on last edited by
      #2

      hi, L"Hellow World" in the MessageBox.

      Uday kiran

      1 Reply Last reply
      0
      • S sawerr

        Hi MessageBox(NULL, "Hello World", "Message Box Title -- Hello World", MB_OK); Error: error C2664: 'MessageBoxW' : cannot convert parameter 2 from 'const char [12]' to 'LPCWSTR' IDE:VS2005 I don't understand why it gives this error. Can you please tell me what the problem is and how i can solve it. Thanks

        F Offline
        F Offline
        fefe wyx
        wrote on last edited by
        #3

        The default project charset setting in VS2005 is using UNICODE, so the MessageBox maps to MessageBoxW, which takes unicode strings as its input. You can 1. changing your project's setting from using UNICODE to MBCS 2. enclose each of the string appeared in your source files with _T(). Or you can do both. The _T macro will map the string to wide char string constant if the project is set to use UNICODE, and will map the string to normal ANSI string constants if the project is set to use MBCS charset.

        S 1 Reply Last reply
        0
        • F fefe wyx

          The default project charset setting in VS2005 is using UNICODE, so the MessageBox maps to MessageBoxW, which takes unicode strings as its input. You can 1. changing your project's setting from using UNICODE to MBCS 2. enclose each of the string appeared in your source files with _T(). Or you can do both. The _T macro will map the string to wide char string constant if the project is set to use UNICODE, and will map the string to normal ANSI string constants if the project is set to use MBCS charset.

          S Offline
          S Offline
          sawerr
          wrote on last edited by
          #4

          thanks for fast reply but for _T("Message Box Title -- Hello World") error C3861: '_T': identifier not found for L"Message Box Title -- Hello World" same error C2664

          S M 2 Replies Last reply
          0
          • S sawerr

            thanks for fast reply but for _T("Message Box Title -- Hello World") error C3861: '_T': identifier not found for L"Message Box Title -- Hello World" same error C2664

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

            sorry friends L is ok. It works.Thank you. But _T macro can not find it says. How can i tell compiler to see this macro.I opened only empty win. application. Thanks again. Edit/Delete Message

            T P 2 Replies Last reply
            0
            • S sawerr

              sorry friends L is ok. It works.Thank you. But _T macro can not find it says. How can i tell compiler to see this macro.I opened only empty win. application. Thanks again. Edit/Delete Message

              T Offline
              T Offline
              toxcct
              wrote on last edited by
              #6

              replace _T() with TEXT()


              TOXCCT >>> GEII power

              [VisualCalc 3.0  updated ][Flags Beginner's Guide  new! ]

              S 1 Reply Last reply
              0
              • T toxcct

                replace _T() with TEXT()


                TOXCCT >>> GEII power

                [VisualCalc 3.0  updated ][Flags Beginner's Guide  new! ]

                S Offline
                S Offline
                sawerr
                wrote on last edited by
                #7

                thanks friends TEXT() is working; also for _T macro #include is solve the problem.

                1 Reply Last reply
                0
                • S sawerr

                  sorry friends L is ok. It works.Thank you. But _T macro can not find it says. How can i tell compiler to see this macro.I opened only empty win. application. Thanks again. Edit/Delete Message

                  P Offline
                  P Offline
                  prasad_som
                  wrote on last edited by
                  #8

                  sawerr wrote:

                  But _T macro can not find it says.

                  What does this mean? _T() macro is defined in tchar.h; But again finally expands to L""

                  Prasad Notifier using ATL

                  1 Reply Last reply
                  0
                  • S sawerr

                    thanks for fast reply but for _T("Message Box Title -- Hello World") error C3861: '_T': identifier not found for L"Message Box Title -- Hello World" same error C2664

                    M Offline
                    M Offline
                    Milton Karimbekallil
                    wrote on last edited by
                    #9

                    what type of project u r using?

                    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