amazing what chatGPT can doAntonio Linares wrote:I just asked chatGPT to write them
This is the result.
will this be the Future of writing CODE ...
amazing what chatGPT can doAntonio Linares wrote:I just asked chatGPT to write them
This is the result.
i have done what you told me and add CODEAntonio Linares wrote:You have to write the Harbour wrappers for those C functions. In example for function BOOL DismountVolume( HANDLE hVolume ):
Code: Select all | Expand
HB_FUNC( DISMOUNTVOLUME )
{
hb_retl( DismountVolume( hb_parnll( 1 ) ) );
}
i have try it also usingError E2342 FWEJECT.prg 203: Type mismatch in parameter 'hVolume' (wanted 'void *', got '__int64') in function HB_FUN_DISMOUNTVOLUME
Code: Select all | Expand
hb_retl( DismountVolume( hb_parnl( 1 ) ) );
what i´m still doing wrongError E2342 FWEJECT.prg 203: Type mismatch in parameter 'hVolume' (wanted 'void *', got 'long') in function HB_FUN_DISMOUNTVOLUME
i have change CODE as you say but still got (same) WarningsEnrico Maria Giordano wrote:Try:Code: Select all | Expand
BOOL fRemoveSafely; // = FALSE; BOOL fAutoEject; // = FALSE;
Code: Select all | Expand
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
CODE is in Sample as "Prototype" (on Top of "C" CODE )What is DismountVolume()? It is not a Windows API.
Code: Select all | Expand
BOOL DismountVolume(HANDLE hVolume);
Code: Select all | Expand
BOOL DismountVolume( HANDLE hVolume)
You are assigning that two variables but never use them. Just remove both of them: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
Code: Select all | Expand
BOOL EjectVolume( TCHAR cDriveLetter )
{
HANDLE hVolume;
hVolume = OpenVolume(cDriveLetter);
if( hVolume == INVALID_HANDLE_VALUE )
return FALSE;
if( ! CloseVolume(hVolume) )
return FALSE;
return TRUE;
}
Code: Select all | Expand
HB_FUNC( DISMOUNTVOLUME )
{
hb_retl( DismountVolume( ( void * ) hb_parnll( 1 ) ) );
}
Code: Select all | Expand
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 ) );
}
Code: Select all | Expand
HANDLE OpenVolume(TCHAR cDriveLetter);
Code: Select all | Expand
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 *')
This is more correct:Antonio Linares wrote:Dear Jimmy,
Code: Select all | Expand
HB_FUNC( DISMOUNTVOLUME ) { hb_retl( DismountVolume( ( void * ) hb_parnll( 1 ) ) ); }
Code: Select all | Expand
HB_FUNC( DISMOUNTVOLUME )
{
hb_retl( DismountVolume( ( HANDLE ) hb_parnll( 1 ) ) );
}
Jimmy wrote:but how with PrototypeCode: Select all | Expand
HANDLE OpenVolume(TCHAR cDriveLetter);
Code: Select all | Expand
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 *')
Code: Select all | Expand
HB_FUNC( OPENVOLUME)
{
hb_retl( OpenVolume( ( TCHAR ) hb_parc( 1 ) ) );
}
ok, i change allEnrico Maria Giordano wrote:This is more correct:Code: Select all | Expand
HB_FUNC( DISMOUNTVOLUME ) { hb_retl( DismountVolume( ( HANDLE ) hb_parnll( 1 ) ) ); }
Code: Select all | Expand
void *
Code: Select all | Expand
HANDLE
i have use it and gotCode: Select all | Expand
HB_FUNC( OPENVOLUME) { hb_retl( OpenVolume( ( TCHAR ) hb_parc( 1 ) ) ); }
Input is IMHO "cDriveLetter" but Return Value is a HANDLE to File which have be openError E2342 FWEJECT.prg 230: Type mismatch in parameter 'iTrueFalse' (wanted 'int', got 'void *') in function HB_FUN_OPENVOLUME
Code: Select all | Expand
HB_FUNC( OPENVOLUME)
{
hb_retnl( ( HANDLE ) OpenVolume( ( TCHAR ) hb_parc( 1 ) ) );
}
Code: Select all | Expand
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 ;
}
YESAntonio Linares wrote: return bResult;
this is my HB_FUNC() QuestionAntonio 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
Code: Select all | Expand
bResult = AutoEjectVolume( hVolume );
if( bResult )
{
CloseVolume( hVolume );
// "where is "ELSE" :?:
}
}
}
}
}