Accueil > > > EJECTER TIROIR CDROM SOUS 95/98/ME
EJECTER TIROIR CDROM SOUS 95/98/ME
Information sur la source
Description
Il ejecte le tiroir du cdrom.
Source
- /*
- Program to programmatically eject removable media from a drive on
- Windows 95.
- */
-
- #include <windows.h>
- #include <stdio.h>
- #include <ctype.h>
-
- //-----------------------------------------------------------------------
- // DeviceIoControl infrastructure
-
- #if !defined (VWIN32_DIOC_DOS_IOCTL)
- #define VWIN32_DIOC_DOS_IOCTL 1
-
- typedef struct _DIOC_REGISTERS {
- DWORD reg_EBX;
- DWORD reg_EDX;
- DWORD reg_ECX;
- DWORD reg_EAX;
- DWORD reg_EDI;
- DWORD reg_ESI;
- DWORD reg_Flags;
- } DIOC_REGISTERS, *PDIOC_REGISTERS;
- #endif
-
- // Intel x86 processor status flags
- #define CARRY_FLAG 0x0001
-
- //-----------------------------------------------------------------------
- // DOS IOCTL function support
-
- #pragma pack(1)
-
- // Parameters for locking/unlocking removable media
- typedef struct _PARAMBLOCK {
- BYTE bOperation;
- BYTE bNumLocks;
- } PARAMBLOCK, *PPARAMBLOCK;
-
- #pragma pack()
-
- //-----------------------------------------------------------------------
- // Win95 low-level media unlocking/removal support
-
- HANDLE WINAPI OpenVWin32 (void);
- BOOL WINAPI CloseVWin32 (HANDLE hVWin32);
- BOOL WINAPI UnlockLogicalVolume (HANDLE hVWin32, BYTE bDriveNum);
- BOOL WINAPI LockLogicalVolume (HANDLE hVWin32,
- BYTE bDriveNum,
- BYTE bLockLevel,
- WORD wPermissions);
- BOOL UnlockMedia (HANDLE hVWin32, BYTE bDrive);
- BOOL EjectMedia (HANDLE hVWin32, BYTE bDrive);
-
- /*-----------------------------------------------------------------------
- main ()
-
- This program ejects media from the specified drive, if the media is
- removable and the device supports software-controlled media removal.
-
- The command line arguments are:
-
- eject drive
-
- For example:
- eject E:
-
- This code works on Windows 95 only, but does not check for Windows 95.
- -----------------------------------------------------------------------*/
- void main (int argc, char **argv)
- {
- HANDLE hVWin32 = INVALID_HANDLE_VALUE;
- BYTE bDrive;
- BOOL fDriveLocked = FALSE;
-
- if (argc !=2)
- {
- printf("usage: eject drive\n");
- return;
- }
-
- // convert command line arg 1 from a drive letter to a DOS drive
- // number
- bDrive = (toupper (argv[1][0]) - 'A') + 1;
-
- hVWin32 = OpenVWin32 ();
-
- // Make sure no other applications are using the drive.
- fDriveLocked = LockLogicalVolume (hVWin32, bDrive, 0, 0);
- if (!fDriveLocked)
- {
- printf("volume %c is in use by another application; therefore, it "
- "cannot be ejected\n", 'A' + bDrive - 1);
- goto CLEANUP_AND_EXIT_APP;
- }
-
- // Make sure there is no software lock keeping the media in the drive.
- if (!UnlockMedia (hVWin32, bDrive))
- {
- printf("could not unlock media from drive %c:\n", 'A' + bDrive - 1);
- goto CLEANUP_AND_EXIT_APP;
- }
-
- // Eject the media
- if (!EjectMedia (hVWin32, bDrive))
- {
- printf("could not eject media from drive %c:\n", 'A' + bDrive - 1);
- }
-
- CLEANUP_AND_EXIT_APP:
- if (fDriveLocked)
- UnlockLogicalVolume (hVWin32, bDrive);
-
- if (hVWin32 != INVALID_HANDLE_VALUE)
- CloseVWin32 (hVWin32);
- }
-
- /*-----------------------------------------------------------------------
- UnlockMedia (hVWin32, bDrive)
-
- Purpose:
- Unlocks removable media from the specified drive so that it can be
- ejected.
-
- Parameters:
- hVWin32
- A handle to VWIN32. Used to issue request to unlock the media.
-
- bDrive
- The logical drive number to unlock. 0 = default, 1 = A, 2 = B,
- etc.
-
- Return Value:
- If successful, returns TRUE; if unsuccessful, returns FALSE.
- -----------------------------------------------------------------------*/
- BOOL UnlockMedia (HANDLE hVWin32, BYTE bDrive)
- {
- DIOC_REGISTERS regs = {0};
- PARAMBLOCK unlockParams = {0};
- int i;
- BOOL fResult;
- DWORD cb;
-
- // First, check the lock status. This way, you'll know the number of
- // pending locks you must unlock.
-
- unlockParams.bOperation = 2; // return lock/unlock status
-
- regs.reg_EAX = 0x440D;
- regs.reg_EBX = bDrive;
- regs.reg_ECX = MAKEWORD(0x48, 0x08);
- regs.reg_EDX = (DWORD)&unlockParams;
-
- fResult = DeviceIoControl (hVWin32, VWIN32_DIOC_DOS_IOCTL,
- ®s, sizeof(regs), ®s, sizeof(regs),
- &cb, 0);
-
- // See if DeviceIoControl and the unlock succeeded.
- if (fResult)
- {
- /*
- DeviceIoControl succeeded. Now see if the unlock succeeded. It
- succeeded if the carry flag is not set, or if the carry flag is
- set but EAX is 0x01 or 0xB0.
-
- It failed if the carry flag is set and EAX is not 0x01 or 0xB0.
-
- If the carry flag is clear, then unlock succeeded. However, you
- don't need to set fResult because it is already TRUE when you get
- in here.
-
- */
- if (regs.reg_Flags & CARRY_FLAG)
- fResult = (regs.reg_EAX == 0xB0) || (regs.reg_EAX == 0x01);
- }
-
- if (!fResult)
- return (FALSE);
-
- // Now, let's unlock the media for every time it has been locked;
- // this will totally unlock the media.
-
- for (i = 0; i < unlockParams.bNumLocks; ++i)
- {
- unlockParams.bOperation = 1; // unlock the media
-
- regs.reg_EAX = 0x440D;
- regs.reg_EBX = bDrive;
- regs.reg_ECX = MAKEWORD(0x48, 0x08);
- regs.reg_EDX = (DWORD)&unlockParams;
-
- fResult = DeviceIoControl (hVWin32, VWIN32_DIOC_DOS_IOCTL,
- ®s, sizeof(regs), ®s, sizeof(regs),
- &cb, 0);
-
- // See if DeviceIoControl and the lock succeeded
- fResult = fResult && !(regs.reg_Flags & CARRY_FLAG);
- if (!fResult)
- break;
- }
- return fResult;
- }
-
- /*-----------------------------------------------------------------------
- EjectMedia (hVWin32, bDrive)
-
- Purpose:
- Ejects removable media from the specified drive.
-
- Parameters:
- hVWin32
- A handle to VWIN32. Used to issue request to unlock the media.
-
- bDrive
- The logical drive number to unlock. 0 = default, 1 = A, 2 = B,
- etc.
-
- Return Value:
- If successful, returns TRUE; if unsuccessful, returns FALSE.
- -----------------------------------------------------------------------*/
- BOOL EjectMedia (HANDLE hVWin32, BYTE bDrive)
- {
- DIOC_REGISTERS regs = {0};
- BOOL fResult;
- DWORD cb;
-
- regs.reg_EAX = 0x440D;
- regs.reg_EBX = bDrive;
- regs.reg_ECX = MAKEWORD(0x49, 0x08);
-
- fResult = DeviceIoControl (hVWin32, VWIN32_DIOC_DOS_IOCTL,
- ®s, sizeof(regs), ®s, sizeof(regs),
- &cb, 0);
-
- // See if DeviceIoControl and the lock succeeded
- fResult = fResult && !(regs.reg_Flags & CARRY_FLAG);
-
- return fResult;
- }
-
- /*-----------------------------------------------------------------------
- OpenVWin32 ()
-
- Purpose:
- Opens a handle to VWIN32 that can be used to issue low-level disk I/O
- commands.
-
- Parameters:
- None.
-
- Return Value:
- If successful, returns a handle to VWIN32.
-
- If unsuccessful, return INVALID_HANDLE_VALUE. Call GetLastError() to
- determine the cause of failure.
- -----------------------------------------------------------------------*/
- HANDLE WINAPI OpenVWin32 (void)
- {
- return CreateFile ("\\\\.\\vwin32", 0, 0, NULL, 0,
- FILE_FLAG_DELETE_ON_CLOSE, NULL);
- }
-
- /*-----------------------------------------------------------------------
- CloseVWin32 (hVWin32)
-
- Purpose:
- Closes the handle opened by OpenVWin32.
-
- Parameters:
- hVWin32
- An open handle to VWIN32.
-
- Return Value:
- If successful, returns TRUE. If unsuccessful, returns FALSE. Call
- GetLastError() to determine the cause of failure.
- -----------------------------------------------------------------------*/
- BOOL WINAPI CloseVWin32 (HANDLE hVWin32)
- {
- return CloseHandle (hVWin32);
- }
-
- /*-----------------------------------------------------------------------
- LockLogicalVolume (hVWin32, bDriveNum, bLockLevel, wPermissions)
-
- Purpose:
- Takes a logical volume lock on a logical volume.
-
- Parameters:
- hVWin32
- An open handle to VWIN32.
-
- bDriveNum
- The logical drive number to lock. 0 = default, 1 = A:, 2 = B:,
- 3 = C:, etc.
-
- bLockLevel
- Can be 0, 1, 2, or 3. Level 0 is an exclusive lock that can only
- be taken when there are no open files on the specified drive.
- Levels 1 through 3 form a hierarchy where 1 must be taken before
- 2, which must be taken before 3.
-
- wPermissions
- Specifies how the lock will affect file operations when lock levels
- 1 through 3 are taken. Also specifies whether a formatting lock
- should be taken after a level 0 lock.
-
- Zero is a valid permission.
-
- Return Value:
- If successful, returns TRUE. If unsuccessful, returns FALSE.
- -----------------------------------------------------------------------*/
- BOOL WINAPI LockLogicalVolume (HANDLE hVWin32,
- BYTE bDriveNum,
- BYTE bLockLevel,
- WORD wPermissions)
- {
- BOOL fResult;
- DIOC_REGISTERS regs = {0};
- BYTE bDeviceCat; // can be either 0x48 or 0x08
- DWORD cb;
-
- /*
- Try first with device category 0x48 for FAT32 volumes. If it
- doesn't work, try again with device category 0x08. If that
- doesn't work, then the lock failed.
- */
-
- bDeviceCat = 0x48;
-
- ATTEMPT_AGAIN:
- // Set up the parameters for the call.
- regs.reg_EAX = 0x440D;
- regs.reg_EBX = MAKEWORD(bDriveNum, bLockLevel);
- regs.reg_ECX = MAKEWORD(0x4A, bDeviceCat);
- regs.reg_EDX = wPermissions;
-
- fResult = DeviceIoControl (hVWin32, VWIN32_DIOC_DOS_IOCTL,
- ®s, sizeof(regs), ®s, sizeof(regs),
- &cb, 0);
-
- // See if DeviceIoControl and the lock succeeded
- fResult = fResult && !(regs.reg_Flags & CARRY_FLAG);
-
- // If DeviceIoControl or the lock failed, and device category 0x08
- // hasn't been tried, retry the operation with device category 0x08.
- if (!fResult && (bDeviceCat != 0x08))
- {
- bDeviceCat = 0x08;
- goto ATTEMPT_AGAIN;
- }
-
- return fResult;
- }
-
- /*-----------------------------------------------------------------------
- UnlockLogicalVolume (hVWin32, bDriveNum)
-
- Purpose:
- Unlocks a logical volume that was locked with LockLogicalVolume().
-
- Parameters:
- hVWin32
- An open handle to VWIN32.
-
- bDriveNum
- The logical drive number to unlock. 0 = default, 1 = A:, 2 = B:,
- 3 = C:, etc.
-
- Return Value:
- If successful, returns TRUE. If unsuccessful, returns FALSE.
-
- Comments:
- Must be called the same number of times as LockLogicalVolume() to
- completely unlock a volume.
-
- Only the lock owner can unlock a volume.
- -----------------------------------------------------------------------*/
- BOOL WINAPI UnlockLogicalVolume (HANDLE hVWin32, BYTE bDriveNum)
- {
- BOOL fResult;
- DIOC_REGISTERS regs = {0};
- BYTE bDeviceCat; // can be either 0x48 or 0x08
- DWORD cb;
-
- /* Try first with device category 0x48 for FAT32 volumes. If it
- doesn't work, try again with device category 0x08. If that
- doesn't work, then the unlock failed.
- */
-
- bDeviceCat = 0x48;
-
- ATTEMPT_AGAIN:
- // Set up the parameters for the call.
- regs.reg_EAX = 0x440D;
- regs.reg_EBX = bDriveNum;
- regs.reg_ECX = MAKEWORD(0x6A, bDeviceCat);
-
- fResult = DeviceIoControl (hVWin32, VWIN32_DIOC_DOS_IOCTL,
- ®s, sizeof(regs), ®s, sizeof(regs),
- &cb, 0);
-
- // See if DeviceIoControl and the unlock succeeded
- fResult = fResult && !(regs.reg_Flags & CARRY_FLAG);
-
- // If DeviceIoControl or the unlock failed, and device category 0x08
- // hasn't been tried, retry the operation with device category 0x08.
- if (!fResult && (bDeviceCat != 0x08))
- {
- bDeviceCat = 0x08;
- goto ATTEMPT_AGAIN;
- }
- return fResult;
- }
/*
Program to programmatically eject removable media from a drive on
Windows 95.
*/
#include <windows.h>
#include <stdio.h>
#include <ctype.h>
//-----------------------------------------------------------------------
// DeviceIoControl infrastructure
#if !defined (VWIN32_DIOC_DOS_IOCTL)
#define VWIN32_DIOC_DOS_IOCTL 1
typedef struct _DIOC_REGISTERS {
DWORD reg_EBX;
DWORD reg_EDX;
DWORD reg_ECX;
DWORD reg_EAX;
DWORD reg_EDI;
DWORD reg_ESI;
DWORD reg_Flags;
} DIOC_REGISTERS, *PDIOC_REGISTERS;
#endif
// Intel x86 processor status flags
#define CARRY_FLAG 0x0001
//-----------------------------------------------------------------------
// DOS IOCTL function support
#pragma pack(1)
// Parameters for locking/unlocking removable media
typedef struct _PARAMBLOCK {
BYTE bOperation;
BYTE bNumLocks;
} PARAMBLOCK, *PPARAMBLOCK;
#pragma pack()
//-----------------------------------------------------------------------
// Win95 low-level media unlocking/removal support
HANDLE WINAPI OpenVWin32 (void);
BOOL WINAPI CloseVWin32 (HANDLE hVWin32);
BOOL WINAPI UnlockLogicalVolume (HANDLE hVWin32, BYTE bDriveNum);
BOOL WINAPI LockLogicalVolume (HANDLE hVWin32,
BYTE bDriveNum,
BYTE bLockLevel,
WORD wPermissions);
BOOL UnlockMedia (HANDLE hVWin32, BYTE bDrive);
BOOL EjectMedia (HANDLE hVWin32, BYTE bDrive);
/*-----------------------------------------------------------------------
main ()
This program ejects media from the specified drive, if the media is
removable and the device supports software-controlled media removal.
The command line arguments are:
eject drive
For example:
eject E:
This code works on Windows 95 only, but does not check for Windows 95.
-----------------------------------------------------------------------*/
void main (int argc, char **argv)
{
HANDLE hVWin32 = INVALID_HANDLE_VALUE;
BYTE bDrive;
BOOL fDriveLocked = FALSE;
if (argc !=2)
{
printf("usage: eject drive\n");
return;
}
// convert command line arg 1 from a drive letter to a DOS drive
// number
bDrive = (toupper (argv[1][0]) - 'A') + 1;
hVWin32 = OpenVWin32 ();
// Make sure no other applications are using the drive.
fDriveLocked = LockLogicalVolume (hVWin32, bDrive, 0, 0);
if (!fDriveLocked)
{
printf("volume %c is in use by another application; therefore, it "
"cannot be ejected\n", 'A' + bDrive - 1);
goto CLEANUP_AND_EXIT_APP;
}
// Make sure there is no software lock keeping the media in the drive.
if (!UnlockMedia (hVWin32, bDrive))
{
printf("could not unlock media from drive %c:\n", 'A' + bDrive - 1);
goto CLEANUP_AND_EXIT_APP;
}
// Eject the media
if (!EjectMedia (hVWin32, bDrive))
{
printf("could not eject media from drive %c:\n", 'A' + bDrive - 1);
}
CLEANUP_AND_EXIT_APP:
if (fDriveLocked)
UnlockLogicalVolume (hVWin32, bDrive);
if (hVWin32 != INVALID_HANDLE_VALUE)
CloseVWin32 (hVWin32);
}
/*-----------------------------------------------------------------------
UnlockMedia (hVWin32, bDrive)
Purpose:
Unlocks removable media from the specified drive so that it can be
ejected.
Parameters:
hVWin32
A handle to VWIN32. Used to issue request to unlock the media.
bDrive
The logical drive number to unlock. 0 = default, 1 = A, 2 = B,
etc.
Return Value:
If successful, returns TRUE; if unsuccessful, returns FALSE.
-----------------------------------------------------------------------*/
BOOL UnlockMedia (HANDLE hVWin32, BYTE bDrive)
{
DIOC_REGISTERS regs = {0};
PARAMBLOCK unlockParams = {0};
int i;
BOOL fResult;
DWORD cb;
// First, check the lock status. This way, you'll know the number of
// pending locks you must unlock.
unlockParams.bOperation = 2; // return lock/unlock status
regs.reg_EAX = 0x440D;
regs.reg_EBX = bDrive;
regs.reg_ECX = MAKEWORD(0x48, 0x08);
regs.reg_EDX = (DWORD)&unlockParams;
fResult = DeviceIoControl (hVWin32, VWIN32_DIOC_DOS_IOCTL,
®s, sizeof(regs), ®s, sizeof(regs),
&cb, 0);
// See if DeviceIoControl and the unlock succeeded.
if (fResult)
{
/*
DeviceIoControl succeeded. Now see if the unlock succeeded. It
succeeded if the carry flag is not set, or if the carry flag is
set but EAX is 0x01 or 0xB0.
It failed if the carry flag is set and EAX is not 0x01 or 0xB0.
If the carry flag is clear, then unlock succeeded. However, you
don't need to set fResult because it is already TRUE when you get
in here.
*/
if (regs.reg_Flags & CARRY_FLAG)
fResult = (regs.reg_EAX == 0xB0) || (regs.reg_EAX == 0x01);
}
if (!fResult)
return (FALSE);
// Now, let's unlock the media for every time it has been locked;
// this will totally unlock the media.
for (i = 0; i < unlockParams.bNumLocks; ++i)
{
unlockParams.bOperation = 1; // unlock the media
regs.reg_EAX = 0x440D;
regs.reg_EBX = bDrive;
regs.reg_ECX = MAKEWORD(0x48, 0x08);
regs.reg_EDX = (DWORD)&unlockParams;
fResult = DeviceIoControl (hVWin32, VWIN32_DIOC_DOS_IOCTL,
®s, sizeof(regs), ®s, sizeof(regs),
&cb, 0);
// See if DeviceIoControl and the lock succeeded
fResult = fResult && !(regs.reg_Flags & CARRY_FLAG);
if (!fResult)
break;
}
return fResult;
}
/*-----------------------------------------------------------------------
EjectMedia (hVWin32, bDrive)
Purpose:
Ejects removable media from the specified drive.
Parameters:
hVWin32
A handle to VWIN32. Used to issue request to unlock the media.
bDrive
The logical drive number to unlock. 0 = default, 1 = A, 2 = B,
etc.
Return Value:
If successful, returns TRUE; if unsuccessful, returns FALSE.
-----------------------------------------------------------------------*/
BOOL EjectMedia (HANDLE hVWin32, BYTE bDrive)
{
DIOC_REGISTERS regs = {0};
BOOL fResult;
DWORD cb;
regs.reg_EAX = 0x440D;
regs.reg_EBX = bDrive;
regs.reg_ECX = MAKEWORD(0x49, 0x08);
fResult = DeviceIoControl (hVWin32, VWIN32_DIOC_DOS_IOCTL,
®s, sizeof(regs), ®s, sizeof(regs),
&cb, 0);
// See if DeviceIoControl and the lock succeeded
fResult = fResult && !(regs.reg_Flags & CARRY_FLAG);
return fResult;
}
/*-----------------------------------------------------------------------
OpenVWin32 ()
Purpose:
Opens a handle to VWIN32 that can be used to issue low-level disk I/O
commands.
Parameters:
None.
Return Value:
If successful, returns a handle to VWIN32.
If unsuccessful, return INVALID_HANDLE_VALUE. Call GetLastError() to
determine the cause of failure.
-----------------------------------------------------------------------*/
HANDLE WINAPI OpenVWin32 (void)
{
return CreateFile ("\\\\.\\vwin32", 0, 0, NULL, 0,
FILE_FLAG_DELETE_ON_CLOSE, NULL);
}
/*-----------------------------------------------------------------------
CloseVWin32 (hVWin32)
Purpose:
Closes the handle opened by OpenVWin32.
Parameters:
hVWin32
An open handle to VWIN32.
Return Value:
If successful, returns TRUE. If unsuccessful, returns FALSE. Call
GetLastError() to determine the cause of failure.
-----------------------------------------------------------------------*/
BOOL WINAPI CloseVWin32 (HANDLE hVWin32)
{
return CloseHandle (hVWin32);
}
/*-----------------------------------------------------------------------
LockLogicalVolume (hVWin32, bDriveNum, bLockLevel, wPermissions)
Purpose:
Takes a logical volume lock on a logical volume.
Parameters:
hVWin32
An open handle to VWIN32.
bDriveNum
The logical drive number to lock. 0 = default, 1 = A:, 2 = B:,
3 = C:, etc.
bLockLevel
Can be 0, 1, 2, or 3. Level 0 is an exclusive lock that can only
be taken when there are no open files on the specified drive.
Levels 1 through 3 form a hierarchy where 1 must be taken before
2, which must be taken before 3.
wPermissions
Specifies how the lock will affect file operations when lock levels
1 through 3 are taken. Also specifies whether a formatting lock
should be taken after a level 0 lock.
Zero is a valid permission.
Return Value:
If successful, returns TRUE. If unsuccessful, returns FALSE.
-----------------------------------------------------------------------*/
BOOL WINAPI LockLogicalVolume (HANDLE hVWin32,
BYTE bDriveNum,
BYTE bLockLevel,
WORD wPermissions)
{
BOOL fResult;
DIOC_REGISTERS regs = {0};
BYTE bDeviceCat; // can be either 0x48 or 0x08
DWORD cb;
/*
Try first with device category 0x48 for FAT32 volumes. If it
doesn't work, try again with device category 0x08. If that
doesn't work, then the lock failed.
*/
bDeviceCat = 0x48;
ATTEMPT_AGAIN:
// Set up the parameters for the call.
regs.reg_EAX = 0x440D;
regs.reg_EBX = MAKEWORD(bDriveNum, bLockLevel);
regs.reg_ECX = MAKEWORD(0x4A, bDeviceCat);
regs.reg_EDX = wPermissions;
fResult = DeviceIoControl (hVWin32, VWIN32_DIOC_DOS_IOCTL,
®s, sizeof(regs), ®s, sizeof(regs),
&cb, 0);
// See if DeviceIoControl and the lock succeeded
fResult = fResult && !(regs.reg_Flags & CARRY_FLAG);
// If DeviceIoControl or the lock failed, and device category 0x08
// hasn't been tried, retry the operation with device category 0x08.
if (!fResult && (bDeviceCat != 0x08))
{
bDeviceCat = 0x08;
goto ATTEMPT_AGAIN;
}
return fResult;
}
/*-----------------------------------------------------------------------
UnlockLogicalVolume (hVWin32, bDriveNum)
Purpose:
Unlocks a logical volume that was locked with LockLogicalVolume().
Parameters:
hVWin32
An open handle to VWIN32.
bDriveNum
The logical drive number to unlock. 0 = default, 1 = A:, 2 = B:,
3 = C:, etc.
Return Value:
If successful, returns TRUE. If unsuccessful, returns FALSE.
Comments:
Must be called the same number of times as LockLogicalVolume() to
completely unlock a volume.
Only the lock owner can unlock a volume.
-----------------------------------------------------------------------*/
BOOL WINAPI UnlockLogicalVolume (HANDLE hVWin32, BYTE bDriveNum)
{
BOOL fResult;
DIOC_REGISTERS regs = {0};
BYTE bDeviceCat; // can be either 0x48 or 0x08
DWORD cb;
/* Try first with device category 0x48 for FAT32 volumes. If it
doesn't work, try again with device category 0x08. If that
doesn't work, then the unlock failed.
*/
bDeviceCat = 0x48;
ATTEMPT_AGAIN:
// Set up the parameters for the call.
regs.reg_EAX = 0x440D;
regs.reg_EBX = bDriveNum;
regs.reg_ECX = MAKEWORD(0x6A, bDeviceCat);
fResult = DeviceIoControl (hVWin32, VWIN32_DIOC_DOS_IOCTL,
®s, sizeof(regs), ®s, sizeof(regs),
&cb, 0);
// See if DeviceIoControl and the unlock succeeded
fResult = fResult && !(regs.reg_Flags & CARRY_FLAG);
// If DeviceIoControl or the unlock failed, and device category 0x08
// hasn't been tried, retry the operation with device category 0x08.
if (!fResult && (bDeviceCat != 0x08))
{
bDeviceCat = 0x08;
goto ATTEMPT_AGAIN;
}
return fResult;
}
Sources du même auteur
Sources de la même categorie
Commentaires et avis
|
Derniers Blogs
SIMULER FACILEMENT L'ENVOI DE MAILSIMULER FACILEMENT L'ENVOI DE MAIL par JeremyJeanson
il m'a été demandé, à plusieurs reprises, comment je faisais pour simuler l'envoi de mail lors de mes démos de Workflow Foundation. Ma solution est plutôt simple : j'utilise la configuration par défaut du SmtpClient et j'oriente les mails vers un dossier ...
Cliquez pour lire la suite de l'article par JeremyJeanson VOTEZ POUR LE TOP 10 DES INFLUENCEURS SHAREPOINT FRANCOPHONES !VOTEZ POUR LE TOP 10 DES INFLUENCEURS SHAREPOINT FRANCOPHONES ! par Patrick Guimonet
Si ce n'est déjà fait (comme plus de 600 personnes déjà), il est encore temps de voter pour le concours TOP 10 des influenceurs SharePoint francophones ! Il est organisé par harmon.ie et accessible ici : http://harmon.ie/top-...
Cliquez pour lire la suite de l'article par Patrick Guimonet [CONF'SHAREPOINT] DERNIER RAPPEL ! :-)[CONF'SHAREPOINT] DERNIER RAPPEL ! :-) par Patrick Guimonet
La Conf'SharePoint en chiffres c'est : 3 jours de SharePoint ! 4 parcours et 60 sessions 17 partenaires représentant toutes les fac...
Cliquez pour lire la suite de l'article par Patrick Guimonet [ #SHAREPOINT 2013 ] LES MODèLES DE SITES STANDARDS.[ #SHAREPOINT 2013 ] LES MODèLES DE SITES STANDARDS. par Patrick Guimonet
C'est un point peu mis en avant mais SharePoint 2013 a été l'occasion de remettre de l'ordre dans les modèles de sites. Tout d'abord, un certain nombre de modèles ont été tout simplement rendus obsolètes (cf. Fonctionnalités déco...
Cliquez pour lire la suite de l'article par Patrick Guimonet
Forum
PB PACMAN C++PB PACMAN C++ par garfield95
Cliquez pour lire la suite par garfield95
Logiciels
Easy-Planning (4.5.0.11)EASY-PLANNING (4.5.0.11)Easy-Planning permet de créer des plannings sous la représentation de diagrammes et est adapté a... Cliquez pour télécharger Easy-Planning CVEasy (3.1.0.51)CVEASY (3.1.0.51)PHMSD-CVEasy est un logiciel d'aide à la rédaction de CV d'une simplicité déconcertante.
PHMSD-C... Cliquez pour télécharger CVEasy LettresFaciles 2011 (8.6.0.31)LETTRESFACILES 2011 (8.6.0.31)LettresFaciles est un logiciel facilitant la création et la rédaction de lettres types.
Son inte... Cliquez pour télécharger LettresFaciles 2011 sDEVIS-FACTURES vlPRO (8.4.2.62)SDEVIS-FACTURES VLPRO (8.4.2.62)sDEVIS-FACTURES vlPRO a été mis au point pour les particuliers, créateurs, entrepreneurs, artisa... Cliquez pour télécharger sDEVIS-FACTURES vlPRO Devis-Factures PHMSD (2.1.0.11)DEVIS-FACTURES PHMSD (2.1.0.11)Configuration minimale
Nécessite Windows™ 2000, XP, Windows 7, 8, Vista (Service Pack à... Cliquez pour télécharger Devis-Factures PHMSD
|