Visual C++ FAQ




Как узнать тип диска? - часть 2


// Function prototypes static BOOL GetDeviceParameters (int nDrive,LPDEVICEPARAMS dp) ; static BOOL IsCDRomDrive (int nDrive) ;

//----------------------------------------------------------------- // GetDeviceParameters() // // Fills a DEVICEPARAMS struct with info about the given drive. // Calls DOS IOCTL Get Device Parameters (440Dh, 60h) function. // // Parameters // nDrive Drive number 0 = A, 1 = B, 2 = C, and so on. // dp Pointer to a structure that will contain the drive's // parameters. // // Returns TRUE if it succeeded, FALSE if it failed. //----------------------------------------------------------------- static BOOL GetDeviceParameters (int nDrive, LPDEVICEPARAMS dp) { BOOL bResult = TRUE; // Assume success __asm { push ds mov bx, nDrive inc bx // Convert 0-based #'s to 1-based #s mov ch, 08h // Device category--must be 08h mov cl, 60h // MS-DOS IOCTL Get Device Parameters lds dx, dp mov ax, 440Dh int 21h jnc gdp_done // CF SET if error mov bResult, FALSE gdp_done: pop ds } return (bResult); } //----------------------------------------------------------------- // IsCDRomDrive() // // Determines if a drive is a CD-ROM. Calls MSCDEX and checks // that MSCDEX is loaded, and that MSCDEX reports the drive is a // CD-ROM. // // Parameters // nDrive Drive number 0 = A, 1 = B, 2 = C, and so forth. // // Returns TRUE if nDrive is a CD-ROM drive, FALSE if it isn't. //----------------------------------------------------------------- static BOOL IsCDRomDrive (int nDrive) { BOOL bResult = FALSE; // Assume not a CD-ROM drive __asm { mov ax, 150Bh // MSCDEX CD-ROM Drive Check xor bx, bx mov cx, nDrive int 2Fh cmp bx, 0ADADh // Check MSCDEX signature jne not_cd_drive or ax, ax // Check the drive type jz not_cd_drive // 0 (zero) means not CD-ROM mov bResult, TRUE not_cd_drive: } return (bResult); }

//----------------------------------------------------------------- UINT GetDriveTypeEx (int nDrive) { DEVICEPARAMS dp; UINT uType; UINT Drv4409Flag ; UINT fAddFlags = 0 ;

_fmemset (&dp, 0, sizeof(dp)); // Init device params struct uType = GetDriveType (nDrive);




Содержание  Назад  Вперед