both Version "seems" to run so far but i got (different) Warnings
bcc7 32 Bit
Warning W8004 .\\HB_FUNC.PRG 132: 'fAutoEject' is assigned a value that is never used in function EjectVolume
Warning W8004 .\\HB_FUNC.PRG 132: 'fRemoveSafely' is assigned a value that is never used in function EjectVolume
Warning W8075 .\\HB_FUNC.PRG 136: Suspicious pointer conversion in function HB_FUN_EJECTREMOVABLE
msvc 64 bit
HB_FUNC.PRG(97): warning C4244: "=": Konvertierung von "BOOL" in "BOOLEAN", möglicher Datenverlust
HB_FUNC.PRG(104): warning C4431: Fehlender Typspezifizierer - int wird angenommen. Hinweis: "default-int" wird von C nicht mehr unterstützt.
HB_FUNC.PRG(136): warning C4090: "Initialisierung": Unterschiedliche "const"-Qualifizierer
who can help me to "fix" both Version
- Code: Select all Expand view
- #pragma begindump
#include <windows.h>
#include <winioctl.h>
#include <tchar.h>
#include <stdio.h>
#include "hbapi.h"
#include "hbapifs.h"
// Prototypes
BOOL EjectVolume(TCHAR cDriveLetter);
HANDLE OpenVolume(TCHAR cDriveLetter);
BOOL LockVolume(HANDLE hVolume);
BOOL DismountVolume(HANDLE hVolume);
BOOL PreventRemovalOfVolume(HANDLE hVolume, BOOL fPrevent);
BOOL AutoEjectVolume(HANDLE hVolume);
BOOL CloseVolume(HANDLE hVolume);
LPTSTR szVolumeFormat = TEXT("\\\\.\\%c:");
LPTSTR szRootFormat = TEXT("%c:\\");
HANDLE OpenVolume(TCHAR cDriveLetter)
{
HANDLE hVolume;
UINT uDriveType;
TCHAR szVolumeName[8];
TCHAR szRootName[5];
DWORD dwAccessFlags;
wsprintf(szRootName, szRootFormat, cDriveLetter);
uDriveType = GetDriveType(szRootName);
switch(uDriveType)
{
case DRIVE_REMOVABLE:
dwAccessFlags = GENERIC_READ | GENERIC_WRITE;
break;
case DRIVE_CDROM:
dwAccessFlags = GENERIC_READ;
break;
default:
return INVALID_HANDLE_VALUE;
}
wsprintf(szVolumeName, szVolumeFormat, cDriveLetter);
hVolume = CreateFile( szVolumeName,
dwAccessFlags,
FILE_SHARE_READ | FILE_SHARE_WRITE,
NULL,
OPEN_EXISTING,
0,
NULL );
return hVolume;
}
BOOL CloseVolume(HANDLE hVolume)
{
return CloseHandle(hVolume);
}
#define LOCK_TIMEOUT 10000 // 10 Seconds
#define LOCK_RETRIES 20
BOOL LockVolume( HANDLE hVolume )
{
DWORD dwBytesReturned;
DWORD dwSleepAmount;
int nTryCount;
dwSleepAmount = LOCK_TIMEOUT / LOCK_RETRIES;
for( nTryCount = 0; nTryCount < LOCK_RETRIES; nTryCount++ )
{
if( DeviceIoControl( hVolume, FSCTL_LOCK_VOLUME, NULL, 0, NULL, 0,
&dwBytesReturned, NULL ) )
return TRUE;
Sleep( dwSleepAmount );
}
return FALSE;
}
BOOL DismountVolume( HANDLE hVolume )
{
DWORD dwBytesReturned;
return DeviceIoControl( hVolume, FSCTL_DISMOUNT_VOLUME, NULL, 0, NULL, 0,
&dwBytesReturned, NULL );
}
BOOL PreventRemovalOfVolume(HANDLE hVolume, BOOL fPreventRemoval)
{
DWORD dwBytesReturned;
PREVENT_MEDIA_REMOVAL PMRBuffer;
PMRBuffer.PreventMediaRemoval = fPreventRemoval;
return DeviceIoControl( hVolume, IOCTL_STORAGE_MEDIA_REMOVAL,
&PMRBuffer, sizeof(PREVENT_MEDIA_REMOVAL),
NULL, 0, &dwBytesReturned, NULL );
}
AutoEjectVolume( HANDLE hVolume )
{
DWORD dwBytesReturned;
return DeviceIoControl( hVolume, IOCTL_STORAGE_EJECT_MEDIA, NULL, 0, NULL, 0,
&dwBytesReturned,
NULL );
}
BOOL EjectVolume( TCHAR cDriveLetter )
{
HANDLE hVolume;
BOOL fRemoveSafely ; // = FALSE;
BOOL fAutoEject ; // = FALSE;
hVolume = OpenVolume(cDriveLetter);
if( hVolume == INVALID_HANDLE_VALUE )
return FALSE;
if( LockVolume(hVolume) && DismountVolume(hVolume) )
fRemoveSafely = TRUE;
{
if (PreventRemovalOfVolume(hVolume, FALSE) && AutoEjectVolume(hVolume))
fAutoEject = TRUE;
}
if( ! CloseVolume(hVolume) )
return FALSE;
return TRUE;
}
HB_FUNC( EJECTREMOVABLE )
{
char * szDrive = hb_parc( 1 );
hb_retl( EjectVolume( ( TCHAR ) *szDrive ) );
return;
}
#pragma enddump