Convert LPCSTR command line parameter to DWORD

Posted on 2004-11-12
Last Modified: 2013-11-20

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,
Question by:dcx45
    LVL 48

    Accepted Solution

    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.
    LVL 4

    Expert Comment

    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


    Author Comment

    Guys, both comments v. helpful, points go to Alex as he was first and the solution worked...

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Threat Intelligence Starter Resources

    Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

    Suggested Solutions

    Title # Comments Views Activity
    string initialization in java 11 94
    only14 challenge 19 57
    modThree challenge 4 51
    pre4 challenge 19 75
    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…
    If you use Adobe Reader X it is possible you can't open OLE PDF documents in the standard. The reason is the 'save box mode' in adobe reader X. Many people think the protected Mode of adobe reader x is only to stop the write access. But this fe…
    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.
    how to add IIS SMTP to handle application/Scanner relays into office 365.

    737 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

    18 Experts available now in Live!

    Get 1:1 Help Now