different Warning using BCC7 32 Bit / MSVC 64 Bit

different Warning using BCC7 32 Bit / MSVC 64 Bit

Postby Jimmy » Thu Dec 15, 2022 1:07 pm

hi,

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
greeting,
Jimmy
User avatar
Jimmy
 
Posts: 1725
Joined: Thu Sep 05, 2019 5:32 am
Location: Hamburg, Germany

Re: different Warning using BCC7 32 Bit / MSVC 64 Bit

Postby Enrico Maria Giordano » Thu Dec 15, 2022 2:02 pm

You have to fix the function EjectVolume() as it is not well written. What this is supposed to mean?

Code: Select all  Expand view
  if( LockVolume(hVolume) && DismountVolume(hVolume) )
     fRemoveSafely = TRUE;
   {
     if (PreventRemovalOfVolume(hVolume, FALSE) && AutoEjectVolume(hVolume))
           fAutoEject = TRUE;
   }
User avatar
Enrico Maria Giordano
 
Posts: 8710
Joined: Thu Oct 06, 2005 8:17 pm
Location: Roma - Italia

Re: different Warning using BCC7 32 Bit / MSVC 64 Bit

Postby Jimmy » Thu Dec 15, 2022 3:00 pm

hi Enricon
Enrico Maria Giordano wrote:You have to fix the function EjectVolume() as it is not well written.

while i had Problem with my DLLCALL Version i have search and found this Version in HMG Forum
https://www.hmgforum.com/viewtopic.php?t=4524

but as i´m not a "C" Programmer i have no Idea how to change CODE

---

Waring around Line 13x are "clear" (so far ...)

but what is "BOOL" vs. "BOOLEAN" which i got using MSVC 64 Bit :?:
i guess it is Parameter BOOL fPreventRemoval

Enrico Maria Giordano wrote:What this is supposed to mean?
Code: Select all  Expand view
  if( LockVolume(hVolume) && DismountVolume(hVolume) )
     fRemoveSafely = TRUE;
   {
     if (PreventRemovalOfVolume(hVolume, FALSE) && AutoEjectVolume(hVolume))
           fAutoEject = TRUE;
   }

Variable fRemoveSafely and fAutoEject are IMHO "not need" ... but how "without" :?:
greeting,
Jimmy
User avatar
Jimmy
 
Posts: 1725
Joined: Thu Sep 05, 2019 5:32 am
Location: Hamburg, Germany

Re: different Warning using BCC7 32 Bit / MSVC 64 Bit

Postby Antonio Linares » Thu Dec 15, 2022 3:04 pm

Dear Jimmy,

Do you mean this code ?
Code: Select all  Expand view
// test program
request hb_gt_win_default
PROC MAIN( cDriveLetter )

    hb_Default( @cDriveLetter, "G:" )

    IF EjectRemovable( cDriveLetter )
        ? "The drive " + cDriveLetter + " can be safely removed."
    ELSE
        ? "Failed to safely remove/eject drive " + cDriveLetter
    ENDIF
    WAIT
    RETURN
// end test program

***************************************************************
#pragma begindump

#include <windows.h>
#include <winioctl.h>
#include <tchar.h>
#include <stdio.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;
}

#include "hbapi.h"
#include "hbapifs.h"
HB_FUNC( EJECTREMOVABLE )
{
    char * szDrive = hb_parc( 1 );
    hb_retl( EjectVolume( *szDrive ) );
    return;
}

#pragma enddump
regards, saludos

Antonio Linares
www.fivetechsoft.com
User avatar
Antonio Linares
Site Admin
 
Posts: 42071
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain

Re: different Warning using BCC7 32 Bit / MSVC 64 Bit

Postby Jimmy » Thu Dec 15, 2022 3:12 pm

hi Antonio,
Antonio Linares wrote:Do you mean this code ?

Yes,
this CODE give me under BCC7 32 Bit this Warnings
Warning W8004 TEST1.prg 147: 'fAutoEject' is assigned a value that is never used in function EjectVolume
Warning W8004 TEST1.prg 147: 'fRemoveSafely' is assigned a value that is never used in function EjectVolume
Warning W8075 TEST1.prg 153: Suspicious pointer conversion in function HB_FUN_EJECTREMOVABLE


as it are "only Warning" and CODE "seems" to work i can use it ... but i don´t like "warning"
greeting,
Jimmy
User avatar
Jimmy
 
Posts: 1725
Joined: Thu Sep 05, 2019 5:32 am
Location: Hamburg, Germany

Re: different Warning using BCC7 32 Bit / MSVC 64 Bit

Postby Enrico Maria Giordano » Thu Dec 15, 2022 4:00 pm

Jimmy wrote:Variable fRemoveSafely and fAutoEject are IMHO "not need" ... but how "without" :?:


Yes, they are not needed because they are not used.
User avatar
Enrico Maria Giordano
 
Posts: 8710
Joined: Thu Oct 06, 2005 8:17 pm
Location: Roma - Italia

Re: different Warning using BCC7 32 Bit / MSVC 64 Bit

Postby Jimmy » Wed Feb 22, 2023 6:30 am

hi,

now i have create own Structure, from Original (and add "X"), but change Member from BOOLEAN to BOOL
Code: Select all  Expand view
typedef struct _PREVENT_MEDIA_REMOVALX {
  BOOL PreventMediaRemoval;
} PREVENT_MEDIA_REMOVALX, *PPREVENT_MEDIA_REMOVALX;

BOOL PreventRemovalOfVolume(HANDLE hVolume, BOOL fPrevent )
{
   DWORD dwBytesReturned;
   PREVENT_MEDIA_REMOVALX PMRBuffer;
   
   PMRBuffer.PreventMediaRemoval = (BOOL) fPrevent ;

   return DeviceIoControl( hVolume, IOCTL_STORAGE_MEDIA_REMOVAL,
                           &PMRBuffer, sizeof(PREVENT_MEDIA_REMOVALX),
                           NULL, 0, &dwBytesReturned, NULL );
}

this now give me no Warning any more :D
greeting,
Jimmy
User avatar
Jimmy
 
Posts: 1725
Joined: Thu Sep 05, 2019 5:32 am
Location: Hamburg, Germany


Return to FiveWin for Harbour/xHarbour

Who is online

Users browsing this forum: Google [Bot] and 58 guests