| | |
List Windows Logical Drive Letters
Please support our C advertiser: Programming Forums - DaniWeb Sister Site
This demonstrates how to get a list of your computer's logical drive letters under the MS-Windows operating system.
#include <windows.h> #include <stdio.h> int main() { char buf[255]; // get the drive letters as a set of strings int sz = GetLogicalDriveStrings(sizeof(buf), buf); if( sz > 0) { // buf now contains a list of all the drive letters. Each drive letter is // terminated with '\0' and the last one is terminated by two consecutive '\0' bytes. char* p1 = buf; char* p2; while( *p1 != '\0' && (p2 = strchr(p1,'\0')) != NULL ) { printf("%s\n", p1); p1 = p2+1; } } else { // Oops! something went wrong so display the error message DWORD dwError = GetLastError(); FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM, 0, dwError, 0, buf, sizeof(buf), 0); printf("%s\n", buf); } }
-2
•
•
•
•
See rather the Microsoft sample.
16 years old... (beginner code for a so simple api, posted 10000 times on BBS & Usenet...)
16 years old... (beginner code for a so simple api, posted 10000 times on BBS & Usenet...)
Last edited by marco93; Nov 12th, 2009 at 2:26 pm.
-7
•
•
•
•
>>See rather the Microsoft sample
What sample? Post link.
[edit] Probably this?
>>posted 10000 times on BBS & Usenet.
Probably -- now its been posted 10001 times
What sample? Post link.
[edit] Probably this?
>>posted 10000 times on BBS & Usenet.
Probably -- now its been posted 10001 times

Last edited by Ancient Dragon; Nov 12th, 2009 at 2:51 pm.
Similar Threads
- Problem installing/ghosting new hard drive (Storage)
- Winxp setup changes drive letters (Windows NT / 2000 / XP)
- Drive letters changed upon installing new CDRW drive! (Windows NT / 2000 / XP)
- Need a list of Windows 2000 Prof. installation files (Windows NT / 2000 / XP)
- Dual Drive Letters in XP PRO~One Drive! (Windows NT / 2000 / XP)
- Change Drive Letters in Windows XP (Windows tips 'n' tweaks)
- XP Disk Manager Drive Letters (Windows NT / 2000 / XP)
| Thread Tools | Search this Thread |
Tag cloud for getlasterror, getlogicaldrivestrin, logical_drives, strchr




