Solved

DWORD

Posted on 2002-06-02
4
696 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: 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

Suggested Solutions

Title # Comments Views Activity
How to convert MFC APP to Win32 APP. 19 112
draw a Christmas tree by using a nested loop? 26 92
DCT of  2D array using fftw in c++ 9 95
How do i run a c++ file? 15 52
IntroductionThis article is the second in a three part article series on the Visual Studio 2008 Debugger.  It provides tips in setting and using breakpoints. If not familiar with this debugger, you can find a basic introduction in the EE article loc…
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 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.
The viewer will learn how to use the return statement in functions in C++. The video will also teach the user how to pass data to a function and have the function return data back for further processing.

733 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