C++实战-获取驱动器的卷标

// DV.cpp : Defines the entry point for the console application.
//C++实战-获取驱动器的卷标
#include "stdafx.h"
#include "windows.h"
#include 
#include 
#include 
using namespace std;
int main(int argc, char* argv[])
{
 DWORD size;
 size=::GetLogicalDriveStrings(0,NULL);
 if(size!=0)
 {
  HANDLE heap=::GetProcessHeap();
  LPSTR lp=(LPSTR)HeapAlloc(heap,HEAP_ZERO_MEMORY,size*sizeof(TCHAR));
  ::GetLogicalDriveStrings(size*sizeof(TCHAR),lp);
  while(*lp!=0)
  {
   UINT res=::GetDriveType(lp);
   if(res=DRIVE_FIXED)
   {
    LPTSTR namebuf=new char[12];
    DWORD namesize=12;
    DWORD serialnumber;
    DWORD maxlen;
    DWORD fileflag;
    LPSTR sysnamebuf=new char[10];
    DWORD sysnamesize=10;
    ::GetVolumeInformation(lp,namebuf,namesize,&serialnumber,&maxlen,&fileflag,sysnamebuf,sysnamesize);
    //temp.Format("%s",namebuf);
    printf("系统磁盘盘符:%s\n卷标:%s\n",lp,namebuf);
   }
   lp=strchr(lp,0)+1;
  }
 }
 return 0;
}

C++实战-获取驱动器的卷标_第1张图片

你可能感兴趣的:(MFC实战,C语言实战)