Home > Windows API > Using GetLogicalDriveStrings!

Using GetLogicalDriveStrings!

I’ve seen people getting stuck with this API mainly because each drive given in the output buffer from this API is NULL terminated and the last entry is double NULL terminated.

So how to extract drives from this API’s output buffer. Here is the code snippet that does this…

TCHAR szDrives[MAX_PATH] = { 0 };
if( GetLogicalDriveStrings( MAX_PATH, szDrives ))
{
   LPTSTR lptszOneDrive = szDrives;
   while( *lptszOneDrive )
   {
      // Do something with one drive
      MessageBox( 0, lptszOneDrive, _T( "Drives" ), MB_OK );

      // Get next drive
      const int nOffset = _tcslen( lptszOneDrive ) + 1;
      lptszOneDrive += nOffset;
   }// End while
}// End if
Advertisements
  1. No comments yet.
  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: