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. Preprocessor question

Preprocessor question

Scheduled Pinned Locked Moved C / C++ / MFC
questionhelpannouncement
5 Posts 3 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.
  • R Offline
    R Offline
    rrrado
    wrote on last edited by
    #1

    How can I use string constant as parameter to function requiring wchar_t* ?

    #define MYSTR "abc"
    // #define MYSTRW L"abc" // I don't like this solution because I have to update the same 2 strings

    wstring x(MYSTR); // error C2664

    thank you

    C S 2 Replies Last reply
    0
    • R rrrado

      How can I use string constant as parameter to function requiring wchar_t* ?

      #define MYSTR "abc"
      // #define MYSTRW L"abc" // I don't like this solution because I have to update the same 2 strings

      wstring x(MYSTR); // error C2664

      thank you

      S Offline
      S Offline
      Stuart Dootson
      wrote on last edited by
      #2

      This MAKELONG macro definition will work for you.

      #include <string>

      #define MYSTR "abc"
      #define MAKELONG2(S) L##S
      #define MAKELONG(S) MAKELONG2(S)

      std::wstring a(MAKELONG(MYSTR));

      Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p

      R 1 Reply Last reply
      0
      • R rrrado

        How can I use string constant as parameter to function requiring wchar_t* ?

        #define MYSTR "abc"
        // #define MYSTRW L"abc" // I don't like this solution because I have to update the same 2 strings

        wstring x(MYSTR); // error C2664

        thank you

        C Offline
        C Offline
        CPallini
        wrote on last edited by
        #3

        use

        #define MYSTR _T("abc")

        and then accordingly define (or not) the UNICODE symbol. :)

        If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
        This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong. -- Iain Clarke
        [My articles]

        1 Reply Last reply
        0
        • S Stuart Dootson

          This MAKELONG macro definition will work for you.

          #include <string>

          #define MYSTR "abc"
          #define MAKELONG2(S) L##S
          #define MAKELONG(S) MAKELONG2(S)

          std::wstring a(MAKELONG(MYSTR));

          Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p

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

          great, thank you :-D I was trying just 1st macro before and I was getting the macro's name in my string :laugh:

          S 1 Reply Last reply
          0
          • R rrrado

            great, thank you :-D I was trying just 1st macro before and I was getting the macro's name in my string :laugh:

            S Offline
            S Offline
            Stuart Dootson
            wrote on last edited by
            #5

            Yup - been there, done that :-)

            Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p

            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