FiveTech Support Forums

FiveWin / Harbour / xBase community
Board index FiveWin for Harbour/xHarbour register callback func to be exec from inside c VM harbour
Posts: 990
Joined: Thu Nov 17, 2005 05:49 PM
register callback func to be exec from inside c VM harbour
Posted: Sun May 28, 2023 09:18 PM
Hello everyone;

I'm looking to register a callback function so that I may show some message while something is happening inside a VM c harbour function. For example to show a progress bar while the Harbour VM c function is inside a for loop.

For example:
Code (fw): Select all Collapse
#define CLAIMKEY_REGEX  "CL[1-2][0-9]-[0-9]{8}"
//----------------------------------------------------------------------------//
METHOD FetchFromScanner() CLASS TBatchPayments
   Local cText := TOCRFromScanner( {|n| ::ShowProgress(n) } )
   Local aOCRClaimKeys := {}
   Local aClaimKeys
Then have the c Wrapper TOCRFromScanner receive and execute ShowProgress inside the for loop.


Any ideas?

Thank you.
Posts: 44158
Joined: Thu Oct 06, 2005 05:47 PM
Re: register callback func to be exec from inside c VM harbour
Posted: Mon May 29, 2023 10:41 AM

Dear Reinaldo,

You may try with:

hb_idleAdd( {|n| ::ShowProgress(n) } )

regards, saludos

Antonio Linares
www.fivetechsoft.com
Posts: 990
Joined: Thu Nov 17, 2005 05:49 PM
Re: register callback func to be exec from inside c VM harbour
Posted: Mon May 29, 2023 03:50 PM
Saludos maestro y gracias por la sugerencia.

I'm sorry I wasn't more specific.

Consider this declaration:
Code (fw): Select all Collapse
//-------------------------------------------------------------------------------
HB_FUNC( TOCRFROMSCANNER )
{
   TOCRJOBINFO_EG    JobInfo_EG;
   TOCRRESULTSEX_EG* Results = 0;
    long                JobNo;
    long                Status;
    long                NumImages = 0;
    long                CntImages = 0;
    HANDLE          *hMems;
    HANDLE          hMMF = 0;
   HB_WCHAR       Msg[10240];   
   HB_WCHAR       FullText[10240] = L"\n"; //final returning string
   char           LogMsg[ TOCRJOBMSGLENGTH ] ;
   HB_WCHAR       pageBreak = L'\u000C';

   memset( Msg, 0, sizeof( Msg ) );  //make sure Msg is empty
   trimTrailing(FullText);
...

               for (long ImgNo = 0; ImgNo < NumImages; ImgNo++) {

                  //show progress using a callback func here 
                  //callback func registered from harbour calling func.

                  if ( hMems[ImgNo] ) {

                     sprintf( LogMsg, "Processing image # %ld.", ImgNo );
                     LogData( "TOCRerr.log", LogMsg, MAX_LOG_SIZE ) ;

                     // convert the memory block to a Memory Mapped File
                     hMMF = ConvertGlobalMemoryToMMF( hMems[ ImgNo ] );
...
I think in order to be able to call a progress function from inside the for loop, we would need to register a callback function that can update a progress bar declared on the calling .prg.

On the Harbour forum Laiton suggested taking a look at hbcurl source where there seems to be something similar. I will try to investigate that.

I will try any other suggestion.

Thank you.

Continue the discussion