Page 3 of 4
Re: DLLCALL under Fivewin
Posted: Thu Dec 08, 2022 10:00 pm
by Jimmy
hi Antonio,
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 ...
Re: DLLCALL under Fivewin
Posted: Fri Dec 09, 2022 8:23 am
by Antonio Linares
who knows...
we will see
Re: DLLCALL under Fivewin
Posted: Fri Dec 09, 2022 1:22 pm
by Jimmy
hi Antonio,
Antonio Linares wrote:You have to write the Harbour wrappers for those C functions. In example for function BOOL DismountVolume( HANDLE hVolume ):
i have done what you told me and add CODE
Code: Select all | Expand
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
i have try it also using
Error E2342 FWEJECT.prg 203: Type mismatch in parameter 'hVolume' (wanted 'void *', got 'long') in function HB_FUN_DISMOUNTVOLUME
what i´m still doing wrong
need Advice please
Re: DLLCALL under Fivewin
Posted: Fri Dec 09, 2022 1:25 pm
by Enrico Maria Giordano
What is DismountVolume()? It is not a Windows API.
Re: DLLCALL under Fivewin
Posted: Fri Dec 09, 2022 1:32 pm
by Jimmy
hi Enrico,
Enrico Maria Giordano wrote:Try:
Code: Select all | Expand
BOOL fRemoveSafely; // = FALSE;
BOOL fAutoEject; // = FALSE;
i have change CODE as you say but still got (same) Warnings
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.
CODE is in Sample as "Prototype" (on Top of "C" CODE )
and "function" begin with
i try to change it to HB_FUNC but again got Type Error Message (see my Answer to Antonio)
p.s. posted CODE "seems" to work even with Warning
Re: DLLCALL under Fivewin
Posted: Fri Dec 09, 2022 2:12 pm
by Enrico Maria Giordano
Jimmy wrote:i have change CODE as you say but still got (same) Warnings
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
You are assigning that two variables but never use them. Just remove both of them:
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;
}
Re: DLLCALL under Fivewin
Posted: Fri Dec 09, 2022 2:34 pm
by Antonio Linares
Dear Jimmy,
Code: Select all | Expand
HB_FUNC( DISMOUNTVOLUME )
{
hb_retl( DismountVolume( ( void * ) hb_parnll( 1 ) ) );
}
Re: DLLCALL under Fivewin
Posted: Fri Dec 09, 2022 3:06 pm
by Jimmy
hi Antonio,
YES, this new CODE compile without Error,thx
so i try "more" and use what chatGPT have answer
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 ) );
}
these new HB_FUNC all compile without Error
but how with Prototype
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 *')
Re: DLLCALL under Fivewin
Posted: Fri Dec 09, 2022 3:28 pm
by Enrico Maria Giordano
Antonio Linares wrote:Dear Jimmy,
Code: Select all | Expand
HB_FUNC( DISMOUNTVOLUME )
{
hb_retl( DismountVolume( ( void * ) hb_parnll( 1 ) ) );
}
This is more correct:
Code: Select all | Expand
HB_FUNC( DISMOUNTVOLUME )
{
hb_retl( DismountVolume( ( HANDLE ) hb_parnll( 1 ) ) );
}
Re: DLLCALL under Fivewin
Posted: Fri Dec 09, 2022 3:31 pm
by Enrico Maria Giordano
Jimmy wrote:but how with Prototype
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 ) ) );
}
Re: DLLCALL under Fivewin
Posted: Fri Dec 09, 2022 3:41 pm
by Jimmy
hi Enrico,
Enrico Maria Giordano wrote:This is more correct:
Code: Select all | Expand
HB_FUNC( DISMOUNTVOLUME )
{
hb_retl( DismountVolume( ( HANDLE ) hb_parnll( 1 ) ) );
}
ok, i change all
to
---
Code: Select all | Expand
HB_FUNC( OPENVOLUME)
{
hb_retl( OpenVolume( ( TCHAR ) hb_parc( 1 ) ) );
}
i have use it and got
Error E2342 FWEJECT.prg 230: Type mismatch in parameter 'iTrueFalse' (wanted 'int', got 'void *') in function HB_FUN_OPENVOLUME
Input is IMHO "cDriveLetter" but Return Value is a HANDLE to File which have be open
Re: DLLCALL under Fivewin
Posted: Fri Dec 09, 2022 3:54 pm
by Enrico Maria Giordano
Try this:
Code: Select all | Expand
HB_FUNC( OPENVOLUME)
{
hb_retnl( ( HANDLE ) OpenVolume( ( TCHAR ) hb_parc( 1 ) ) );
}
Re: DLLCALL under Fivewin
Posted: Mon Dec 26, 2022 4:35 am
by Jimmy
hi,
i have re-write CODE this Way
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 ;
}
i use if( bResult ) for next Step
but how ("where") to return FALSE; when fail ?
or better MsgInfo() before return FALSE;
need some help please
Re: DLLCALL under Fivewin
Posted: Mon Dec 26, 2022 7:32 am
by Antonio Linares
Dear Jimmy,
Simply replace this:
return TRUE ;
with
return bResult;
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
Re: DLLCALL under Fivewin
Posted: Mon Dec 26, 2022 9:10 am
by Jimmy
hi Antonio,
Antonio Linares wrote:
return bResult;
YES
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
this is my HB_FUNC() Question
Code: Select all | Expand
bResult = AutoEjectVolume( hVolume );
if( bResult )
{
CloseVolume( hVolume );
// "where is "ELSE" :?:
}
}
}
}
}
how can i put some "Output" Error Message into "ELSE-Level"