converting LPDWORD to DWORD

This is a discussion on converting LPDWORD to DWORD within the C++ Programming forums, part of the General Programming Boards category; How do I do that? Please and thanks....

  1. #1
    Registered User Queatrix's Avatar
    Join Date
    Apr 2005
    Posts
    1,342

    Lightbulb converting LPDWORD to DWORD

    How do I do that?
    Please and thanks.

  2. #2
    ZuK
    ZuK is offline
    Registered User
    Join Date
    Aug 2005
    Location
    Austria
    Posts
    1,990
    Code:
    LPDWORD pw;
    DWORD w = *pw;
    kurt

  3. #3
    Registered User Queatrix's Avatar
    Join Date
    Apr 2005
    Posts
    1,342
    No errors from the compiler, but the "Program Error" message came up when it hit that scipt.

  4. #4
    I am me, who else?
    Join Date
    Oct 2002
    Posts
    250
    Well yes, usually you would need something in the LPDWORD....

    Like for instance...

    Code:
    LPDWORD pw = NULL;
    getsomedwordval( pw );
    DWORD w = *pw;
    or

    Code:
    LPDWORD pw = NULL;
    DWORD x = 123456;
    pw = &x;
    DWORD w = *pw;

    Where getsomedwordval fills in the pw variable... and really always init pointers to be NULL!
    Last edited by dpro; 09-06-2005 at 02:09 PM. Reason: Adding clarity(I hope)

  5. #5
    Registered User Queatrix's Avatar
    Join Date
    Apr 2005
    Posts
    1,342
    I don't understand your scripts.
    So here is why I wanted to know:
    Code:
      LPCTSTR lpRootPathName = "C:\\";
      LPDWORD lpSectorsPerCluster = 0;
      LPDWORD lpBytesPerSector = 0;
      LPDWORD lpNumberOfFreeClusters = 0;
      LPDWORD lpTotalNumberOfClusters = 0;
      GetDiskFreeSpace(lpRootPathName,lpSectorsPerCluster,lpBytesPerSector,lpNumberOfFreeClusters,lpTotalNumberOfClusters);
      char* user;
      wsprintf(user,"Sectors Per Cluster: %d\r\n",dwSectorsPerCluster);
      if(dwSectorsPerCluster > 0)
      MessageBox(hwnd, user, "C:\\/%Details%/", MB_OK | MB_ICONINFORMATION);
    From what I know, it's the wsprintf() function that creates the error.

  6. #6
    Registered User
    Join Date
    Jan 2005
    Posts
    7,338
    LPDWORD is a pointer to a DWORD. You set these pointers to 0 (or null). That means they don't point at anything. GetDiskFreeSpace expects them to point at valid memory. A better solution would be to make those variables DWORDS, and pass the address of them to the function.

  7. #7
    I am me, who else?
    Join Date
    Oct 2002
    Posts
    250
    Then use *dwSectorsPerCluster because you are telling wsprintf to display an int(DWORD), yet you are supplying it a pointer to a DWORD (LPDWORD). It tries to use the pointer, but it cannot figure out what you mean, so either use *dwSectorsPerCluster or tell wsprintf to use a pointer to an int , (I believe it is %n , but check msdn to be sure ).


    LPDWORD is a pointer to a DWORD. You set these pointers to 0 (or null). That means they don't point at anything. GetDiskFreeSpace expects them to point at valid memory. A better solution would be to make those variables DWORDS, and pass the address of them to the function.
    Actually that is somewhat wrong unfortunately ( click here for why ), these are "out" pointers so they are fine being NULL'd however wsprintf has fits if you give it something wrong.
    Last edited by dpro; 09-06-2005 at 02:42 PM.

  8. #8
    Registered User
    Join Date
    Jan 2005
    Posts
    7,338
    >> these are "out" pointers so they are fine being NULL'd

    This is incorrect. The pointer cannot be null, because there would be no way to return the data. When you have an "out" variable, you must pass it by pointer or reference, otherwise the local version will not get updated. In this case, they expect you to have local DWORD variables and pass them by pointer to the function to get updated.

  9. #9
    I am me, who else?
    Join Date
    Oct 2002
    Posts
    250
    Doh I hate it when I make a mistake but you are right. Sorry about that Daved, should've thought about that more carefully.
    Last edited by dpro; 09-06-2005 at 03:34 PM.

  10. #10
    Registered User Queatrix's Avatar
    Join Date
    Apr 2005
    Posts
    1,342
    Thanks for your help.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Help calling function is asm
    By brietje698 in forum C++ Programming
    Replies: 24
    Last Post: 12-06-2007, 03:48 PM
  2. Inline asm
    By brietje698 in forum C++ Programming
    Replies: 5
    Last Post: 11-11-2007, 01:54 PM
  3. Getting position from game..
    By brietje698 in forum C++ Programming
    Replies: 1
    Last Post: 10-26-2007, 12:15 PM
  4. Converting a DWORD to INT
    By MK4554 in forum C++ Programming
    Replies: 5
    Last Post: 04-11-2006, 02:57 PM
  5. storage size of regs is unkown
    By Vertex34 in forum C Programming
    Replies: 5
    Last Post: 11-04-2003, 09:17 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21