Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

Programming Talk / C++ / C# - Converting string to dword

Author
Message
Ashy
19
Years of Service
User Offline
Joined: 1st Nov 2005
Location:
Posted: 23rd Aug 2006 14:42
Hey guys, how would i go about converting a string variable (or even a char) to a dword? I've tried casting it but I get an error..

Quote: "1>.\main.cpp(108) : error C2440: 'type cast' : cannot convert from 'std::string' to 'DWORD'
1> No user-defined-conversion operator available that can perform this conversion, or the operator cannot be called"


I am new to c++ and have been messing around rearranging stuff trying to cast (DWORD) .etc in front, in the function call .etc .etc just to see if something works. Any help?

Code;
IanM
Retired Moderator
22
Years of Service
User Offline
Joined: 11th Sep 2002
Location: In my moon base
Posted: 23rd Aug 2006 15:14
You have the solution in your own code, where you are using dbPrint.

You can't cast an object to an integral type (DWORD in your case), but you can get the pointer to the characters (using the c_str method), and cast that to a dword.

Instead of this


Do this


Ashy
19
Years of Service
User Offline
Joined: 1st Nov 2005
Location:
Posted: 23rd Aug 2006 15:29
Thankyee Ian
EddieB
20
Years of Service
User Offline
Joined: 29th Sep 2004
Location: United Kingdom
Posted: 25th Aug 2006 10:58
Why on earth are you calling win32 functions from dgsdk :o

Dude!?!

Look at the functions I left in your other thread.. they are correct and work well... there's no need what so ever to do what you are doing.
Ashy
19
Years of Service
User Offline
Joined: 1st Nov 2005
Location:
Posted: 26th Aug 2006 14:56
Sorry ed.. while i appreaciate your help I couldn't get them to work. Copy and pasting straight from the page gave me errors (can't remember what, was awhile ago) it was
Quote: "1>.\main.cpp(119) : error C2664: 'GetPrivateProfileIntW' : cannot convert parameter 1 from 'char *' to 'LPCWSTR'
1> Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast"
So i cast them, but it still doesn't create the ini file, so i try editing the code to include the full path name but still no file (as msdn sez it creates it in the registry by default unless you specify a pathname). Also, isn't it WritePrivateProfileStringA - "A" for ANSCI, "W" for unicode...? Plus I kinda figured out my way mostly by myself except for afew typecasts.. i'll most likely change it all over to c++ in time, once i've learned enough i'll realise to full extent what i'm doing now is just lame

Thanks very much for offering help tho.
IanG
20
Years of Service
User Offline
Joined: 25th Sep 2004
Location: Cyberspace
Posted: 26th Aug 2006 16:57
Quote: "Also, isn't it WritePrivateProfileStringA - "A" for ANSCI, "W" for unicode...?"

A is for ASCII and W is for wide iirc, which is the same as unicode really


amd athlon xp 2600+,1280mb,FX 5200 128mb,200gb & 120gb,xp pro sp2

Login to post a reply

Server time is: 2025-05-22 03:38:43
Your offset time is: 2025-05-22 03:38:43