CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 9 of 9

Thread: DWORD to string

  1. #1
    Join Date
    Jan 2006
    Posts
    15

    DWORD to string

    Does anyone know how to convert a DWORD to a string, or char* or char[], or CString etc.

    What I am trying to do is read a DWORD value from the registry and put its value in an edit box in a MFC Dialog. And then when the user clicks OK, I'll take that value they typed into the edit box(if they changed it) and put that back into the Registry.

    I found out how to go from char* to DWORD but I can't figure out how to go the other way around so when I first read that value from the Registry I can update the edit box with it.

    Basically I am trying to display a DWORD value in an edit box.

    Thanks
    Last edited by JL8843; February 27th, 2006 at 11:08 AM.

  2. #2
    Join Date
    May 2004
    Location
    London, England
    Posts
    563

    Re: DWORD to string

    Have a look at the following link.

    Regards
    I don't mind that you think slowly but I do mind that you are publishing faster than you think. Wolfgang Pauli, physicist, Nobel laureate (1900-1958)

  3. #3
    Join Date
    Oct 2002
    Location
    Timisoara, Romania
    Posts
    14,360

    Re: DWORD to string

    Take a look at these FAQs.
    Marius Bancila
    Home Page
    My CodeGuru articles

    I do not offer technical support via PM or e-mail. Please use vbBulletin codes.

  4. #4
    Join Date
    Jan 2006
    Posts
    15

    Re: DWORD to string

    Thanks for your responses.

    I guess I have to convert the DWORD into an int or decimal representation first for it to display correctly in the edit box.


    Right now it is displaying 3i in my edit box.

    How would you go about converting the DWORD value into a decimal value?

  5. #5
    Join Date
    Mar 2003
    Location
    India {Mumbai};
    Posts
    3,871

    Re: DWORD to string

    DWORD is nothing by 'typedef' for unsigned long. It hold value within its range.
    It is upto programmer how to represent it, how to store value in it - decimal, hexa decimal or octal format; or to use it in calculations or as return value of some expression/function.

    Can you be more specific, what you want to achieve?
    My latest article: Explicating the new C++ standard (C++0x)

    Do rate the posts you find useful.

  6. #6
    Join Date
    Jul 2005
    Location
    Germany
    Posts
    1,194

    Re: DWORD to string

    Either with the C runtime function ltoa():
    Code:
    #include <stdlib.h>
    
    char buffer[32];
    ltoa((long)dwValue, buffer, 10);
    Or with the WinAPI function wsprinf():
    Code:
    #include <windows.h>
    
    char buffer[32];
    wsprintf(buffer, "%d", dwValue);
    Please don't forget to rate users who helped you!

  7. #7
    Join Date
    Jun 2002
    Location
    Moscow, Russia.
    Posts
    2,176

    Re: DWORD to string

    Quote Originally Posted by JL8843
    Thanks for your responses.

    I guess I have to convert the DWORD into an int or decimal representation first for it to display correctly in the edit box.


    Right now it is displaying 3i in my edit box.

    How would you go about converting the DWORD value into a decimal value?
    Did you read FAQ cilu suggested?
    "Programs must be written for people to read, and only incidentally for machines to execute."

  8. #8
    Join Date
    Jan 2006
    Posts
    15

    Re: DWORD to string

    Quote Originally Posted by RoboTact
    Did you read FAQ cilu suggested?
    Yes, I think that I am now able to load the DWORD value into the edit box.

    I am still confused however with writing back to the registry.

    How do I go about converting an int to a DWORD? Is this just a simple cast?

  9. #9
    Join Date
    Oct 2002
    Location
    Timisoara, Romania
    Posts
    14,360

    Re: DWORD to string

    Yes, it's a simple cast between two numeric types. DWORD is actually defined as unsigned int.
    Marius Bancila
    Home Page
    My CodeGuru articles

    I do not offer technical support via PM or e-mail. Please use vbBulletin codes.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured