Solved

DWORD

Posted on 2002-06-02
4
692 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
  • 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

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

Templates For Beginners Or How To Encourage The Compiler To Work For You Introduction This tutorial is targeted at the reader who is, perhaps, familiar with the basics of C++ but would prefer a little slower introduction to the more ad…
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…
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.
The viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.

746 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now