DLLCALL under Fivewin

Re: DLLCALL under Fivewin

Postby Jimmy » Thu Dec 08, 2022 10:00 pm

hi Antonio,
Antonio Linares wrote:I just asked chatGPT to write them :-)
This is the result.

amazing what chatGPT can do :D

will this be the Future of writing CODE ...
greeting,
Jimmy
User avatar
Jimmy
 
Posts: 1732
Joined: Thu Sep 05, 2019 5:32 am
Location: Hamburg, Germany

Re: DLLCALL under Fivewin

Postby Antonio Linares » Fri Dec 09, 2022 8:23 am

who knows...

we will see :-)
regards, saludos

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

Re: DLLCALL under Fivewin

Postby Jimmy » Fri Dec 09, 2022 1:22 pm

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 view  RUN
   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
Code: Select all  Expand view  RUN
      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

what i´m still doing wrong :(
need Advice please
greeting,
Jimmy
User avatar
Jimmy
 
Posts: 1732
Joined: Thu Sep 05, 2019 5:32 am
Location: Hamburg, Germany

Re: DLLCALL under Fivewin

Postby Enrico Maria Giordano » Fri Dec 09, 2022 1:25 pm

What is DismountVolume()? It is not a Windows API.
User avatar
Enrico Maria Giordano
 
Posts: 8718
Joined: Thu Oct 06, 2005 8:17 pm
Location: Roma - Italia

Re: DLLCALL under Fivewin

Postby Jimmy » Fri Dec 09, 2022 1:32 pm

hi Enrico,
Enrico Maria Giordano wrote:Try:
Code: Select all  Expand view  RUN
BOOL fRemoveSafely; // = FALSE;
BOOL fAutoEject; // = FALSE;

Code: Select all  Expand view  RUN
hb_retl( EjectVolume( ( TCHAR ) *szDrive ) );

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 )
Code: Select all  Expand view  RUN
BOOL DismountVolume(HANDLE hVolume);


and "function" begin with
Code: Select all  Expand view  RUN
BOOL DismountVolume( HANDLE hVolume)


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

Re: DLLCALL under Fivewin

Postby Enrico Maria Giordano » Fri Dec 09, 2022 2:12 pm

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 view  RUN
BOOL EjectVolume( TCHAR cDriveLetter )
{
   HANDLE hVolume;

   hVolume = OpenVolume(cDriveLetter);
   if( hVolume == INVALID_HANDLE_VALUE )
     return FALSE;

   if( ! CloseVolume(hVolume) )
     return FALSE;

   return TRUE;
}
User avatar
Enrico Maria Giordano
 
Posts: 8718
Joined: Thu Oct 06, 2005 8:17 pm
Location: Roma - Italia

Re: DLLCALL under Fivewin

Postby Antonio Linares » Fri Dec 09, 2022 2:34 pm

Dear Jimmy,

Code: Select all  Expand view  RUN
HB_FUNC( DISMOUNTVOLUME )
{
    hb_retl( DismountVolume( ( void * ) hb_parnll( 1 ) ) );
}
regards, saludos

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

Re: DLLCALL under Fivewin

Postby Jimmy » Fri Dec 09, 2022 3:06 pm

hi Antonio,

YES, this new CODE compile without Error,thx :)

so i try "more" and use what chatGPT have answer

Code: Select all  Expand view  RUN
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 :D

but how with Prototype
Code: Select all  Expand view  RUN
HANDLE OpenVolume(TCHAR cDriveLetter);

Code: Select all  Expand view  RUN
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 *')
greeting,
Jimmy
User avatar
Jimmy
 
Posts: 1732
Joined: Thu Sep 05, 2019 5:32 am
Location: Hamburg, Germany

Re: DLLCALL under Fivewin

Postby Enrico Maria Giordano » Fri Dec 09, 2022 3:28 pm

Antonio Linares wrote:Dear Jimmy,

Code: Select all  Expand view  RUN
HB_FUNC( DISMOUNTVOLUME )
{
    hb_retl( DismountVolume( ( void * ) hb_parnll( 1 ) ) );
}


This is more correct:

Code: Select all  Expand view  RUN
HB_FUNC( DISMOUNTVOLUME )
{
    hb_retl( DismountVolume( ( HANDLE ) hb_parnll( 1 ) ) );
}
User avatar
Enrico Maria Giordano
 
Posts: 8718
Joined: Thu Oct 06, 2005 8:17 pm
Location: Roma - Italia

Re: DLLCALL under Fivewin

Postby Enrico Maria Giordano » Fri Dec 09, 2022 3:31 pm

Jimmy wrote:but how with Prototype
Code: Select all  Expand view  RUN
HANDLE OpenVolume(TCHAR cDriveLetter);

Code: Select all  Expand view  RUN
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 view  RUN
HB_FUNC( OPENVOLUME)
{
   hb_retl( OpenVolume( ( TCHAR ) hb_parc( 1 ) ) );
}
User avatar
Enrico Maria Giordano
 
Posts: 8718
Joined: Thu Oct 06, 2005 8:17 pm
Location: Roma - Italia

Re: DLLCALL under Fivewin

Postby Jimmy » Fri Dec 09, 2022 3:41 pm

hi Enrico,
Enrico Maria Giordano wrote:This is more correct:
Code: Select all  Expand view  RUN
HB_FUNC( DISMOUNTVOLUME )
{
    hb_retl( DismountVolume( ( HANDLE ) hb_parnll( 1 ) ) );
}

ok, i change all
Code: Select all  Expand view  RUN
void *

to
Code: Select all  Expand view  RUN
HANDLE


---
Code: Select all  Expand view  RUN
   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
greeting,
Jimmy
User avatar
Jimmy
 
Posts: 1732
Joined: Thu Sep 05, 2019 5:32 am
Location: Hamburg, Germany

Re: DLLCALL under Fivewin

Postby Enrico Maria Giordano » Fri Dec 09, 2022 3:54 pm

Try this:

Code: Select all  Expand view  RUN
HB_FUNC( OPENVOLUME)
{
    hb_retnl( ( HANDLE ) OpenVolume( ( TCHAR ) hb_parc( 1 ) ) );
}
User avatar
Enrico Maria Giordano
 
Posts: 8718
Joined: Thu Oct 06, 2005 8:17 pm
Location: Roma - Italia

Re: DLLCALL under Fivewin

Postby Jimmy » Mon Dec 26, 2022 4:35 am

hi,

i have re-write CODE this Way

Code: Select all  Expand view  RUN
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
greeting,
Jimmy
User avatar
Jimmy
 
Posts: 1732
Joined: Thu Sep 05, 2019 5:32 am
Location: Hamburg, Germany

Re: DLLCALL under Fivewin

Postby Antonio Linares » Mon Dec 26, 2022 7:32 am

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
regards, saludos

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

Re: DLLCALL under Fivewin

Postby Jimmy » Mon Dec 26, 2022 9:10 am

hi Antonio,
Antonio Linares wrote:return bResult;

YES :D

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 view  RUN
              bResult = AutoEjectVolume( hVolume );
               if( bResult )
               {
                  CloseVolume( hVolume );
               // "where is "ELSE"  :?:
               }
            }
         }
      }
   }

how can i put some "Output" Error Message into "ELSE-Level" :?:
greeting,
Jimmy
User avatar
Jimmy
 
Posts: 1732
Joined: Thu Sep 05, 2019 5:32 am
Location: Hamburg, Germany

PreviousNext

Return to FiveWin for Harbour/xHarbour

Who is online

Users browsing this forum: No registered users and 55 guests