Antonio Linares wrote:I just asked chatGPT to write them
This is the result.
amazing what chatGPT can do
will this be the Future of writing CODE ...
Antonio Linares wrote:I just asked chatGPT to write them
This is the result.
Antonio Linares wrote:You have to write the Harbour wrappers for those C functions. In example for function BOOL DismountVolume( HANDLE hVolume ):
HB_FUNC( DISMOUNTVOLUME )
{
hb_retl( DismountVolume( hb_parnll( 1 ) ) );
}
Error E2342 FWEJECT.prg 203: Type mismatch in parameter 'hVolume' (wanted 'void *', got '__int64') in function HB_FUN_DISMOUNTVOLUME
hb_retl( DismountVolume( hb_parnl( 1 ) ) );
Error E2342 FWEJECT.prg 203: Type mismatch in parameter 'hVolume' (wanted 'void *', got 'long') in function HB_FUN_DISMOUNTVOLUME
Enrico Maria Giordano wrote:Try:
- Code: Select all Expand view
BOOL fRemoveSafely; // = FALSE;
BOOL fAutoEject; // = FALSE;
- Code: Select all Expand view
hb_retl( EjectVolume( ( TCHAR ) *szDrive ) );
Warning W8004 FWEJECT.prg 190: 'fAutoEject' is assigned a value that is never used in function EjectVolume
Warning W8004 FWEJECT.prg 190: 'fRemoveSafely' is assigned a value that is never used in function EjectVolume
Warning W8075 FWEJECT.prg 196: Suspicious pointer conversion in function HB_FUN_EJECTREMOVABLE
What is DismountVolume()? It is not a Windows API.
BOOL DismountVolume(HANDLE hVolume);
BOOL DismountVolume( HANDLE hVolume)
Jimmy wrote:i have change CODE as you say but still got (same) WarningsWarning W8004 FWEJECT.prg 190: 'fAutoEject' is assigned a value that is never used in function EjectVolume
Warning W8004 FWEJECT.prg 190: 'fRemoveSafely' is assigned a value that is never used in function EjectVolume
BOOL EjectVolume( TCHAR cDriveLetter )
{
HANDLE hVolume;
hVolume = OpenVolume(cDriveLetter);
if( hVolume == INVALID_HANDLE_VALUE )
return FALSE;
if( ! CloseVolume(hVolume) )
return FALSE;
return TRUE;
}
HB_FUNC( DISMOUNTVOLUME )
{
hb_retl( DismountVolume( ( void * ) hb_parnll( 1 ) ) );
}
HB_FUNC( LOCKVOLUME)
{
hb_retl( LockVolume( ( void * ) hb_parnll( 1 ) ) );
}
HB_FUNC( DISMOUNTVOLUME )
{
hb_retl( DismountVolume( ( void * ) hb_parnll( 1 ) ) );
}
HB_FUNC( AUTOEJECTVOLUME)
{
hb_retl( AutoEjectVolume( ( void * ) hb_parnll( 1 ) ) );
}
HB_FUNC( CLOSEVOLUME)
{
hb_retl( CloseVolume( ( void * ) hb_parnll( 1 ) ) );
}
HB_FUNC( PREVENTREMOVALOFVOLUME )
{
hb_retl( PreventRemovalOfVolume( ( void * ) hb_parnll( 1 ), FALSE ) );
}
HANDLE OpenVolume(TCHAR cDriveLetter);
HB_FUNC( OPENVOLUME)
{
hb_retl( OpenVolume(hb_parc( 1 )) );
}
Error E2342 FWEJECT.prg 230: Type mismatch in parameter 'cDriveLetter' (wanted 'signed char', got 'const signed char *')
Antonio Linares wrote:Dear Jimmy,
- Code: Select all Expand view
HB_FUNC( DISMOUNTVOLUME )
{
hb_retl( DismountVolume( ( void * ) hb_parnll( 1 ) ) );
}
HB_FUNC( DISMOUNTVOLUME )
{
hb_retl( DismountVolume( ( HANDLE ) hb_parnll( 1 ) ) );
}
Jimmy wrote:but how with Prototype
- Code: Select all Expand view
HANDLE OpenVolume(TCHAR cDriveLetter);
- Code: Select all Expand view
HB_FUNC( OPENVOLUME)
{
hb_retl( OpenVolume(hb_parc( 1 )) );
}
Error E2342 FWEJECT.prg 230: Type mismatch in parameter 'cDriveLetter' (wanted 'signed char', got 'const signed char *')
HB_FUNC( OPENVOLUME)
{
hb_retl( OpenVolume( ( TCHAR ) hb_parc( 1 ) ) );
}
Enrico Maria Giordano wrote:This is more correct:
- Code: Select all Expand view
HB_FUNC( DISMOUNTVOLUME )
{
hb_retl( DismountVolume( ( HANDLE ) hb_parnll( 1 ) ) );
}
void *
HANDLE
- Code: Select all Expand view
HB_FUNC( OPENVOLUME)
{
hb_retl( OpenVolume( ( TCHAR ) hb_parc( 1 ) ) );
}
Error E2342 FWEJECT.prg 230: Type mismatch in parameter 'iTrueFalse' (wanted 'int', got 'void *') in function HB_FUN_OPENVOLUME
HB_FUNC( OPENVOLUME)
{
hb_retnl( ( HANDLE ) OpenVolume( ( TCHAR ) hb_parc( 1 ) ) );
}
BOOL EjectVolume( TCHAR cDriveLetter )
{
HANDLE hVolume;
BOOL bResult;
// BOOL fRemoveSafely = FALSE;
// BOOL fAutoEject = FALSE;
hVolume = OpenVolume(cDriveLetter);
if( hVolume != INVALID_HANDLE_VALUE )
{
bResult = LockVolume( hVolume );
if( bResult )
{
bResult = DismountVolume( hVolume );
if( bResult )
{
bResult = PreventRemovalOfVolume( hVolume, FALSE );
if( bResult )
{
bResult = AutoEjectVolume( hVolume );
if( bResult )
{
CloseVolume( hVolume );
}
}
}
}
}
// 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 ;
}
Antonio Linares wrote:return bResult;
Antonio Linares wrote:next is to write the Harbour wrapper for it and then from there you can check the returned value and show a msg if desired,
though usually it is a better practice to leave the developer warn about it in case of an error
bResult = AutoEjectVolume( hVolume );
if( bResult )
{
CloseVolume( hVolume );
// "where is "ELSE" :?:
}
}
}
}
}
Return to FiveWin for Harbour/xHarbour
Users browsing this forum: No registered users and 81 guests