Jump to content

WinExists function with empty text parameter


hp38guser
 Share

Recommended Posts

I'm converting my existing AutoIt script to Object Pascal (Inno Setup). I can access AutoIt functions and even the WinExists function works but I have to specify a text to search for. When using null I get an Acces Violation error: Read of Address 00000000. When I do specify a window text to search for it works, but how can I use null as a parameter? Other external dlls accept null parameters, but I need this to work with AutoItX.

function AU3_WinExists(
        title: string;
        text: string
        ): integer;
    external 'AU3_WinExists@files:autoitx3.dll';

    if AU3_WinExists('Notepad', '') <> 0 then
        MsgBox('AutoIt detected Notepad', mbError, mb_OK);

I tested using AutoItX 3.2.12.1 and 3.2.13.7 beta.

Edited by hp38guser
Link to comment
Share on other sites

That looks more like a problem with Object Pascal. It's passing a null instead of a blank string. I don't know enough about the language to tell you how to make it do otherwise, but I'm guessing that is the problem.

I'm still a novice programmer, but what's the difference between an empty string and null? I might be able to use SetLength(Str, 0) to create an empty string. Thanks anyway ;)

Link to comment
Share on other sites

The difference between an empty string and null is that the empty string is a value. It's a string with a length of 0 characters. A null on the other hand is a value given to a pointer to indicate that it doesn't contain any value.

Like, think of memory as a set of boxes. We've got a box for a string. The empty string won't have any letters in its "box." The null, doesn't even have a box. Does that make sense?

Chr(0) isn't exactly the right solution, but it will work.

Edited by Richard Robertson
Link to comment
Share on other sites

  • 1 month later...

The difference between an empty string and null is that the empty string is a value. It's a string with a length of 0 characters. A null on the other hand is a value given to a pointer to indicate that it doesn't contain any value.

Like, think of memory as a set of boxes. We've got a box for a string. The empty string won't have any letters in its "box." The null, doesn't even have a box. Does that make sense?

Chr(0) isn't exactly the right solution, but it will work.

A String in Pascal is not a pointer to a char array as a string is in C so I think it should be converted to Pchar.

Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.
Link to comment
Share on other sites

  • 1 month later...

I could be wrong... but I got a simular issue in autoit.

Basically I had a loop that would wait until a Window does not exist and then ExitLoop... but it would never detect that the window did not exist anymore. Even though there were no windows with that name. I noticed that it would only work if I used a text in it.

Does not work when the window is closed:

While 1
    If Not WinExists('SUPERAntiSpyware') Then Exitloop
    Sleep(100)
WEnd

This does work (Thanks to the person who started this thread for the idea):

While 1
    If Not WinExists('SUPERAntiSpyware', chr(0)) Then Exitloop
    Sleep(100)
WEnd

This happens with the latest stable and Beta release of Autoit.

Can others test this and see what results they get? I really think there is a bug here.

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
 Share

  • Recently Browsing   0 members

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