Solved

DWORD

Posted on 2002-06-02
4
698 Views
Last Modified: 2008-03-06
Hi, I'm newbie in c++ and I can't solve this probllem:


I have:
char * mychar = "0xffff0000";
DWORD color;

I want to put mychar into color like I usually do:
color = 0xffff0000;



Tnx.
0
Comment
Question by:Romonnn
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
4 Comments
 
LVL 86

Expert Comment

by:jkr
ID: 7049687
use 'strtol()':

#include <stdlib.h>

cahr * pc;
char * mychar = "0xffff0000";
DWORD color;

color = strtol ( mychar, &pc, 16); // 16 indicates hex numeric base

if ( *pc) {
// error
}
0
 

Author Comment

by:Romonnn
ID: 7049766
jkr, this is the best answer on my question. But, the output of strtol still not the same. The output is 2147483647 but it should be 4294901760 (approximately 2 * 2147483647). As a newbie i tried 32 as 3 argument of strtol(output 0). I still don't know what to do :(



#include <stdlib.h>
#include <iostream.h>
#include <windows.h>


int main(){


char * pc;
char * mychar = "0xffff0000";
DWORD color;
DWORD color2 = 0xffff0000;

color = strtol ( mychar, &pc, 16); // 16 indicates hex numeric base

cout << color << endl;
cout << color2 << endl;


if ( *pc) {
// error
}
}
0
 
LVL 86

Accepted Solution

by:
jkr earned 100 total points
ID: 7049773
My fault - use "strtoul()" instead...
0
 

Author Comment

by:Romonnn
ID: 7049810
Tnx. Everything works fine :)
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Many modern programming languages support the concept of a property -- a class member that combines characteristics of both a data member and a method.  These are sometimes called "smart fields" because you can add logic that is applied automaticall…
Container Orchestration platforms empower organizations to scale their apps at an exceptional rate. This is the reason numerous innovation-driven companies are moving apps to an appropriated datacenter wide platform that empowers them to scale at a …
The goal of the video will be to teach the user the concept of local variables and scope. An example of a locally defined variable will be given as well as an explanation of what scope is in C++. The local variable and concept of scope will be relat…
The viewer will be introduced to the technique of using vectors in C++. The video will cover how to define a vector, store values in the vector and retrieve data from the values stored in the vector.

717 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question