• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 710
  • Last Modified:

DWORD

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
Romonnn
Asked:
Romonnn
  • 2
  • 2
1 Solution
 
jkrCommented:
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
 
RomonnnAuthor Commented:
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
 
jkrCommented:
My fault - use "strtoul()" instead...
0
 
RomonnnAuthor Commented:
Tnx. Everything works fine :)
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now