[Last Call] Learn about multicloud storage options and how to improve your company's cloud strategy. Register Now

x
?
Solved

DWORD

Posted on 2002-06-02
4
Medium Priority
?
708 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 400 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: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering 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

In days of old, returning something by value from a function in C++ was necessarily avoided because it would, invariably, involve one or even two copies of the object being created and potentially costly calls to a copy-constructor and destructor. A…
This article will show you some of the more useful Standard Template Library (STL) algorithms through the use of working examples.  You will learn about how these algorithms fit into the STL architecture, how they work with STL containers, and why t…
The goal of the video will be to teach the user the difference and consequence of passing data by value vs passing data by reference in C++. An example of passing data by value as well as an example of passing data by reference will be be given. Bot…
The viewer will learn how to pass data into a function in C++. This is one step further in using functions. Instead of only printing text onto the console, the function will be able to perform calculations with argumentents given by the user.
Suggested Courses

650 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