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

    [RESOLVED] Converting DWORD to CString

    I have a DWORD variable and want to convert to a CString.

    Likewise, I would like to convert a CString to a DWORD.

    I know how to do it for other variables using functions like

    [code]
    number = atoi(str); //string to number
    str.Format("%d", number); //number to string
    [/ccode]

    I would appreciate any suggestions and example code.


  2. #2
    Join Date
    Jun 1999
    Posts
    9

    Re: Converting DWORD to CString

    Try this.


    CString MyString;
    DWORD SomeNum;
    MyString.Format ("%d", SomeNum);




    Lee

  3. #3
    Andrew Truckle Guest

    Re: Converting DWORD to CString

    surely %d is a normal interger, not a DWORD?
    And what about string to DWORD?


  4. #4
    Join Date
    Jun 1999
    Posts
    9

    Re: Converting DWORD to CString

    Sorry, you should use "%u" instead of "%d" since "%u" is for unsigned ints (which is a DWORD). As far as converting from DWORD to string, I do not know of any unsigned int versions of atoi().

    Lee

  5. #5
    Andrew Truckle Guest

    Re: Converting DWORD to CString

    Yes - %u

    And I thought about it - I could use sscanf to convert from string to DWORD:

    [code]
    DWORD var;
    CString MyStr = "1234";
    sscanf(MyStr, "%u", &var);
    [/ccode]

    I think that would work ok.


  6. #6
    Join Date
    Jun 1999
    Posts
    9

    Re: Converting DWORD to CString

    Actually, there is a function called strtoul, which converts strings to unsigned longs.


    unsigned long strtoul( const char *nptr, char **endptr, int base );





    Lee

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