Jump to content

COM (VB6) events are handled with a delay in AutoIt


Go to solution Solved by trancexx,

Recommended Posts

I've an AutoIt script that uses a COM-object (created with VB6). The COM-object can fire events. I would like to use these events to display progress of a task in the AutoIt script, because the execution of the VB6 task can take up to 10 minutes. The problem is that the events are being fired, but that they are handled in AutoIt after the processing of the  'huge' task has ended. Below you can find a reduced version of the script. In the real-life version of the script a GUI is used and the progress percentage should not be written to the console, but to the inner text of a 'DIV' element.


Func Work()
    Local $g_oReport = ObjCreate("wcDashboardTools.DashBoardToolsVB6")

    If IsObj($g_oReport) Then

        $g_oReport.Server = "my-sql-server-name"
        Local $g_oReportEvents = ObjEvent($g_oReport,"ToolsEvent_")  ; Start receiving Events.
; test the events three times (the 'InitEvents' methods only raises the event in VB6)   
; in the test application this works and the event messages now have been written to the console
; in the real life application, these 'test' messages will only be written to the console after the report results have been rendered
        $g_oReport.Database = "my-database-name"
        $g_oReport.FinancialYear = 2013
        $g_oReport.FinancialPeriodStart = 1
        $g_oReport.FinancialPeriodEnd = 1
        $g_oReport.ReportLayout = "my-layout-name"
; start the huge task
 ; at this point, the huge task has been completed
        ConsoleWrite("Creation of the report finished, start rendering the report")
        If @Compiled = 0 Then $g_oReport.StoreReportAsXml("c:\temp\exploreport.xml")
; start rendering
        $sHTML = $g_oReport.GetReportAsHtmlString()
        ConsoleWrite("FOUT: Het genereren van de rapportage is mislukt.")


Func ToolsEvent_OnTaskProgressChange($taskProgress)

    ConsoleWrite('Progress(%): ' & $taskProgress & @CRLF)


The 'CreateReport' method of the COM-object fires the event two times before actually starting the 'huge' task itself. However, the messages for these events only will be written to the console after the rendered HTML is written to the console.

Can anybody help me to make sure that the events are handled within the AutoIt script at the correct moment (during execution of the 'huge' task)?

Thanks in advance!


P.S. I made a reference implementation in C# which uses the same VB6 (Interop) and then the events are handled at the correct moment.

Link to comment
Share on other sites

I had a similar experience.  I wrote an ActiveXControl in Delphi 5 to do Message Boxes with stylized background colors.  You could add a Help Button to the message box.  It used the help event to call a function with an integer param(the help context.)  It worked in C#, C++, VB, but, as in your case, the help dialog from pressing the Help Button was only shown after the user closed the message dialog, in AutoIt3.  For this reason I don't think the likelihood of a fix is high.  It's just how AutoIt3 is put together.

Edited by MilesAhead
Link to comment
Share on other sites

Thanks Trancexx! I tried the 'volatile' keyword with Beta versio and now the timing of the event handling is how it should be. Unfortunately, we use AutoIt for a business critical application, so using a beta version is not on my wish list.

I will try to find another solution (display progress from within the COM-classes or something like that), but I appreciate your answer very much!

Link to comment
Share on other sites

  • Moderators


Look back here in a few days time - you might find that your "Beta aversion" is no longer a problem. Although that particular section of the code is unlikely to have been changed from what is currently available. ;)


Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:


ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area


Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

  • Recently Browsing   0 members

    • No registered users viewing this page.
  • Create New...