How do I do that?
Please and thanks.
How do I do that?
Please and thanks.
kurtCode:LPDWORD pw; DWORD w = *pw;
No errors from the compiler, but the "Program Error" message came up when it hit that scipt.
Well yes, usually you would need something in the LPDWORD....
Like for instance...
orCode:LPDWORD pw = NULL; getsomedwordval( pw ); DWORD w = *pw;
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)
I don't understand your scripts.
So here is why I wanted to know:
From what I know, it's the wsprintf() function that creates the error.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);
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.
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 ).
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.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.
Last edited by dpro; 09-06-2005 at 02:42 PM.
>> 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.
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.