WinApi学习笔记-获取光驱中的信息

2022-05-09 11:08:21 浏览数 (1)

代码语言:javascript复制
#include <windows.h>
#include <stdlib.h>
#include <stdio.h>
#include <cstring>

#define BUFSIZE 1024

int main(void)
{
	CHAR buf[BUFSIZE];
	PCHAR SzDrive; //CHAR的指针;
	CHAR myMessage[BUFSIZE];
	GetLogicalDriveStrings(BUFSIZE-1,buf);
	SzDrive = (PCHAR)buf;
	DWORD dwLastErr;
	DWORD dwFileSystemFlags;
	while(GetDriveType(SzDrive) != DRIVE_CDROM)
	{
		SzDrive  = (lstrlen(SzDrive) 1);
	}	
	if(!GetVolumeInformation(
		SzDrive,NULL,0,NULL,NULL,&dwFileSystemFlags,buf,BUFSIZE
		))
	{
		dwLastErr = GetLastError();
		if(dwLastErr == 21)
		{
			MessageBox(NULL,"请放入光盘","提示",MB_OK);
			return 0;
		}
	}
	MessageBox(NULL,buf,"提示文件系统类别",MB_OK);
	return 0;
}

0 人点赞