Page 1 of 1

register callback func to be exec from inside c VM harbour

Posted: Sun May 28, 2023 9:18 pm
by reinaldocrespo
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: Select all | Expand

#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.

Re: register callback func to be exec from inside c VM harbour

Posted: Mon May 29, 2023 10:41 am
by Antonio Linares
Dear Reinaldo,

You may try with:

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

Re: register callback func to be exec from inside c VM harbour

Posted: Mon May 29, 2023 3:50 pm
by reinaldocrespo
Saludos maestro y gracias por la sugerencia.

I'm sorry I wasn't more specific.

Consider this declaration:

Code: Select all | Expand

//-------------------------------------------------------------------------------
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.