[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Convert LPCSTR command line parameter to DWORD

Posted on 2004-11-12
3
Medium Priority
?
469 Views
Last Modified: 2013-11-20
Hi,

rookie question:

I'm using API that expects DWORD value as one of its parameters. Other parameters use LPCSTR and work fine. How do I convert and pass this value from the command line? I don't really care what format the command-line param will be in- it can be either a number or the XXXX_DISABLED string.

Many thanks,
0
Comment
Question by:dcx45
3 Comments
 
LVL 48

Accepted Solution

by:
AlexFM earned 375 total points
ID: 12564769
You can convert string to number using atoi function or sscanf. sscanf returns number of successfully converted characters, this allows to test whether command line contains valid number.
0
 
LVL 4

Expert Comment

by:Skonen
ID: 12575185
strtoul converts a string to an unsigned long (DWORD):
strtoul(const char *nptr,  char **endptr,  int base);


So in your case, if you have an LPCSTR named "lpszStr" you may want to use:

DWORD dwValue = strtoul(lpszStr, NULL, NULL);


The function's prototype is located in stdlib.h, so be sure to include it...

Good luck,
      Stuart Konen

0
 

Author Comment

by:dcx45
ID: 12615603
Guys, both comments v. helpful, points go to Alex as he was first and the solution worked...
0

Featured Post

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

Question has a verified solution.

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

Introduction: The undo support, implementing a stack. Continuing from the eigth article about sudoku.   We need a mechanism to keep track of the digits entered so as to implement an undo mechanism.  This should be a ‘Last In First Out’ collec…
Introduction: Dialogs (1) modal - maintaining the database. Continuing from the ninth article about sudoku.   You might have heard of modal and modeless dialogs.  Here with this Sudoku application will we use one of each type: a modal dialog …
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
Are you ready to place your question in front of subject-matter experts for more timely responses? With the release of Priority Question, Premium Members, Team Accounts and Qualified Experts can now identify the emergent level of their issue, signal…
Suggested Courses
Course of the Month18 days, 10 hours left to enroll

834 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