How to convert a CString to DWORD in C++
-
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
-
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
Assuming you're doing a Unicode build, the
GetBuffer()
call is unnecessary. The first param towcstod()
is aLPCWSTR
, andCString
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? -
Assuming you're doing a Unicode build, the
GetBuffer()
call is unnecessary. The first param towcstod()
is aLPCWSTR
, andCString
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?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.
-
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
Although you already have an answer to the
CString
-related issue, I note that you are usingwcstod(...)
instead ofwcstoul(...)
. I could understand if you might be handing strings that contain values in the higher ranges of thedouble
type, but you are truncating them via the cast toDWORD
... Passing anunsigned short
type as the second parameter to thewcstod(...)
function might be technically incorrect now, too; it should bewchar_t
, aswchar_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!)