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. ATL / WTL / STL
  4. How to convert a CString to DWORD in C++

How to convert a CString to DWORD in C++

Scheduled Pinned Locked Moved ATL / WTL / STL
c++csharpdotnetvisual-studiohelp
4 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.
  • C Offline
    C Offline
    ClockDivider
    wrote on last edited by
    #1

    Hello, I just switsched from C++ 6.0 to VS .NET, and some code that compiled before does not compile any more: CString cNum = "123"; unsigned short* ss; DWORD dwRet = (DWORD)wcstod(cNum.GetBuffer(0),&ss); error C2664: 'wcstod': conversion of parameter 1 von 'ATL::CSimpleStringT::PXSTR' into 'const wchar_t *' impossible What do I have to do? I do NOT want to use the .NET framework nor ATL, only MFC? I suppose I have to switch some compiler parameters? Thanks a lot! Martin

    M J 2 Replies Last reply
    0
    • C ClockDivider

      Hello, I just switsched from C++ 6.0 to VS .NET, and some code that compiled before does not compile any more: CString cNum = "123"; unsigned short* ss; DWORD dwRet = (DWORD)wcstod(cNum.GetBuffer(0),&ss); error C2664: 'wcstod': conversion of parameter 1 von 'ATL::CSimpleStringT::PXSTR' into 'const wchar_t *' impossible What do I have to do? I do NOT want to use the .NET framework nor ATL, only MFC? I suppose I have to switch some compiler parameters? Thanks a lot! Martin

      M Offline
      M Offline
      Michael Dunn
      wrote on last edited by
      #2

      Assuming you're doing a Unicode build, the GetBuffer() call is unnecessary. The first param to wcstod() is a LPCWSTR, and CString has a conversion operator that will be called automatically. --Mike-- Visual C++ MVP :cool: LINKS~! Ericahist | 1ClickPicGrabber | NEW~! CP SearchBar v3.0 | C++ Forum FAQ Ford, what's this fish doing in my ear?

      C 1 Reply Last reply
      0
      • M Michael Dunn

        Assuming you're doing a Unicode build, the GetBuffer() call is unnecessary. The first param to wcstod() is a LPCWSTR, and CString has a conversion operator that will be called automatically. --Mike-- Visual C++ MVP :cool: LINKS~! Ericahist | 1ClickPicGrabber | NEW~! CP SearchBar v3.0 | C++ Forum FAQ Ford, what's this fish doing in my ear?

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

        Thanks a lot, due to your answer i was able to get the code compiling now. I thought new .NET projects were unicode by default, as i could not find a switch. but now i found it and it works fine.... i appreciate it very much, thanks.... Martin.

        1 Reply Last reply
        0
        • C ClockDivider

          Hello, I just switsched from C++ 6.0 to VS .NET, and some code that compiled before does not compile any more: CString cNum = "123"; unsigned short* ss; DWORD dwRet = (DWORD)wcstod(cNum.GetBuffer(0),&ss); error C2664: 'wcstod': conversion of parameter 1 von 'ATL::CSimpleStringT::PXSTR' into 'const wchar_t *' impossible What do I have to do? I do NOT want to use the .NET framework nor ATL, only MFC? I suppose I have to switch some compiler parameters? Thanks a lot! Martin

          J Offline
          J Offline
          James R Twine
          wrote on last edited by
          #4

          Although you already have an answer to the CString-related issue, I note that you are using wcstod(...) instead of wcstoul(...).    I could understand if you might be handing strings that contain values in the higher ranges of the double type, but you are truncating them via the cast to DWORD...    Passing an unsigned short type as the second parameter to the wcstod(...) function might be technically incorrect now, too; it should be wchar_t, as wchar_t is (can map to) a native type in VC++ .Net and above (see __wchar_t for details).    Peace! -=- James


          If you think it costs a lot to do it right, just wait until you find out how much it costs to do it wrong!
          Tip for new SUV drivers: Professional Driver on Closed Course does not mean your Dumb Ass on a Public Road!
          DeleteFXPFiles & CheckFavorites (Please rate this post!)

          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