Sign in to follow this  
Followers 0
Zulqarnain

AdlibRegister() Confusion

9 posts in this topic

Hi, Following is the code for a program which I am using to test AdlibRegister()'s capability to work-around the error dialog boxes.

[My real problem was: Using DriveGetDrive('all') which returned empty drives - empty drives caused an error to popup which says 'Drive not ready, insert disk' etc. I solved the error using DriveStatus()]

* While browsing through the help file I found the AdlibRegister() which is supposed to handle these types of errors.

* I now want to test this functionality of AdlibRegister() - For future usage.

* The following code pops up an Error DialogBox every 30 seconds, verifies if the PID of dialog box is same as AutoIt compiled script and then kills the dialog box.

* The functionality is straightforward, but AdlibRegister() doesn't get called.

All I need is someone who'll give me a hazy idea of what I'm doing wrong. I don't need a complete solution, I'd like to reach to the solution myself.

Any help is highly appreciated. (I'm a beginner, started a month ago with AutoIt.)

$gPID = @AutoItPID
AdlibRegister("ErrorRemover",30)


dbg('gPID:1:' & $gPID)
While 1
    Sleep(1000 * 30)
    MsgBox(4096, "AutoIt3 Error: Error has occured!", "Ok Dude!")
    Sleep(1000 * 30)
WEnd


Func ErrorRemover()
    If WinExists("Error") Then
        Local $lPID = WinGetProcess("Error")
        dbg('lPID:2:' & $lPID)
        dbg('gPID:2:' & $gPID)
        If $lPID == $gPID Then
            WinClose("Error")
        EndIf
    EndIf
EndFunc   ;==>ErrorRemover

Func dbg($msg)
    DllCall("kernel32.dll", "none", "OutputDebugString", "str", $msg)
EndFunc   ;==>dbg

Share this post


Link to post
Share on other sites



Zulqarnain,

There's nothing wrong with AdLibRegister(). I added a ConsoleWrite() function to the ErrorRemover() function and there is written something in my console. Your mistake is in the first line of your function. You look for a window called 'Error'. Your MsgBox() made doesn't have the name Error. Can you say 1=4??? No, you can't. This is the same. 'AutoIt3 Error: Error has occured! = Error'. Is that true?? No, I don't think so. You have to read the whole title of the window, not just a piece of it. Do you understand?? I think you must have enough with this information.


PowerSlide2UnlockiPhone look-a-like program you can use to lock your pc, you can't access your desktop again until the password is entered and the slider slided to the right. (really proud of it)-- After a time AutoIt and Windows, I switched to Mac. Don't expect me to answer anymore.

Share this post


Link to post
Share on other sites

Zulqarnain,

There's nothing wrong with AdLibRegister(). I added a ConsoleWrite() function to the ErrorRemover() function and there is written something in my console. Your mistake is in the first line of your function. You look for a window called 'Error'. Your MsgBox() made doesn't have the name Error. Can you say 1=4??? No, you can't. This is the same. 'AutoIt3 Error: Error has occured! = Error'. Is that true?? No, I don't think so. You have to read the whole title of the window, not just a piece of it. Do you understand?? I think you must have enough with this information.

Thank You for replying AppTux, here is a quote from the AutoIt Help File:

AutoIt operates in one of three "Window matching" modes. The modes are set with the AutoItSetOption function using the WinTitleMatchMode option.

The default option is 'Match Partial titles' so 'Error, Err, Auto, It3' everything should match! [That is also the reason I added the PID filter - I don't want a Word document like 'Types of Error in Physics' getting closed accidentally.

Thank you for your patience.

Share this post


Link to post
Share on other sites

The default mode is "Match the title [partial] from the start" and not "match any substring", so you would have to modify that setting.


*GERMAN* [note: you are not allowed to remove author / modified info from my UDFs]My UDFs:[_SetImageBinaryToCtrl] [_TaskDialog] [AutoItObject] [Animated GIF (GDI+)] [ClipPut for Image] [FreeImage] [GDI32 UDFs] [GDIPlus Progressbar] [Hotkey-Selector] [Multiline Inputbox] [MySQL without ODBC] [RichEdit UDFs] [SpeechAPI Example] [WinHTTP]UDFs included in AutoIt: FTP_Ex (as FTPEx), _WinAPI_SetLayeredWindowAttributes

Share this post


Link to post
Share on other sites

The default mode is "Match the title [partial] from the start" and not "match any substring", so you would have to modify that setting.

Thank you so much for the explanation! I misinterpreted it. :)

The new code:

Opt("WinTitleMatchMode", 2)

$gPID = @AutoItPID
AdlibRegister("ErrorRemover",30)


dbg('gPID:1:' & $gPID)
While 1
    Sleep(1000 * 30)
    MsgBox(4096, "AutoIt3 Error: Error has occured!", "Ok Dude!")
    Sleep(1000 * 30)
WEnd


Func ErrorRemover()
    If WinExists("Error") Then
        Local $lPID = WinGetProcess("Error")
        dbg('lPID:2:' & $lPID)
        dbg('gPID:2:' & $gPID)
        If $lPID == $gPID Then
            WinClose("Error")
        EndIf
    EndIf
EndFunc   ;==>ErrorRemover

Func dbg($msg)
    DllCall("kernel32.dll", "none", "OutputDebugString", "str", $msg)
EndFunc   ;==>dbg

Even this doesn't work - The Sysinternals DebugView should show the output of the function ErrorRemover() but it doesn't - That implies that the system doesn't enter the function at all.

If it is of any help, I'm running the script as a compiled exe.

Share this post


Link to post
Share on other sites

#6 ·  Posted (edited)

The Messagebox in the script interrupts the script and all Adlib-functions.

If you have messageboxes in the same script and you don't want to show them, you should replace them and not reading and closing them in an Adlib-function.

Edited by ProgAndy

*GERMAN* [note: you are not allowed to remove author / modified info from my UDFs]My UDFs:[_SetImageBinaryToCtrl] [_TaskDialog] [AutoItObject] [Animated GIF (GDI+)] [ClipPut for Image] [FreeImage] [GDI32 UDFs] [GDIPlus Progressbar] [Hotkey-Selector] [Multiline Inputbox] [MySQL without ODBC] [RichEdit UDFs] [SpeechAPI Example] [WinHTTP]UDFs included in AutoIt: FTP_Ex (as FTPEx), _WinAPI_SetLayeredWindowAttributes

Share this post


Link to post
Share on other sites

The Messagebox in the script interrupts the script and all Adlib-functions.

Exactly my thought! - thanks for confirming.

Just one more question: It is impossible to use AdlibRegister() to close error MessageBoxes generated by the AutoItExe - in other words, a script cannot unblock itself? [Y/N]

This was the example in the AutoIt Help file that prompted me to try this in the first place:

AdlibRegister("MyAdlib")
;...
Exit

Func MyAdlib()
    ;... execution must be non blocking, avoid ...Wait(), MsgBox(), InputBox() functions
    If WinActive("Error") Then
        ;...
    EndIf
EndFunc

Share this post


Link to post
Share on other sites

No, there is no way to overcome this restriction since AutoIt does not support threads.

Maybe timers set with _Timer_SetTimer will work, but I am not sure.


*GERMAN* [note: you are not allowed to remove author / modified info from my UDFs]My UDFs:[_SetImageBinaryToCtrl] [_TaskDialog] [AutoItObject] [Animated GIF (GDI+)] [ClipPut for Image] [FreeImage] [GDI32 UDFs] [GDIPlus Progressbar] [Hotkey-Selector] [Multiline Inputbox] [MySQL without ODBC] [RichEdit UDFs] [SpeechAPI Example] [WinHTTP]UDFs included in AutoIt: FTP_Ex (as FTPEx), _WinAPI_SetLayeredWindowAttributes

Share this post


Link to post
Share on other sites

No, there is no way to overcome this restriction since AutoIt does not support threads.

Maybe timers set with _Timer_SetTimer will work, but I am not sure.

Thank you for your patience and excellent replies. :)

My problem is now solved:

Simply include another AutoIt compiled Exe with your Primary script.

The secondary script will cycle through the available windows and when it finds one labelled 'Error' it'll compare its PID with the PID of the primary function - If PID is confirmed, it'll kill the window.

[Disadvantage of This Method]

It'll add an extra 298kB of weight to your Primary Exe :)

Share this post


Link to post
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
Sign in to follow this  
Followers 0