Wednesday 22 May 2013

Win32 API - Code Sample to Know Drive Names

This code sample shows each drive letter in a message-box and also stores them in the “drives” array.
Number of drives found is stored in “drive_count” variable.
/******* Get all drives available *******/

char buffer[1024];
char *drives[10];
int drive_count = 0;
GetLogicalDriveStringsA(512, buffer);
for (int i = 0; i < 10; i++) { drives[i] = (char *) malloc(4); } // Allocate mem for 20 elements
char *ptr = buffer;
while (*ptr) {
MessageBoxA(NULL, ptr, "Drive", MB_OK); // Display each drive in a messagebox
strcpy(drives[drive_count], ptr);
drive_count++;
ptr = &ptr[strlen(ptr)+1];
}

for (int i = 0; i < 10; i++) { free(drives[i]); } // Free mem for drives

Check  Out My Rank On PRTracking.com!

0 comments:

Post a Comment

All Articles © Asit. No Copying. Powered by Blogger.
 
Copyright © . The Tech Veda - Posts · Comments
Markup Powered by Bluefish Editor 2.2