Sign in to follow this  
Followers 0
hp38guser

WinExists function with empty text parameter

10 posts in this topic

#1 ·  Posted (edited)

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

Share this post


Link to post
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.

Share this post


Link to post
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 ;)

Share this post


Link to post
Share on other sites

I tried using Chr(0) as parameter and it seems to fix it. Thanks ;)

Share this post


Link to post
Share on other sites

#5 ·  Posted (edited)

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

Share this post


Link to post
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.

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.

Share this post


Link to post
Share on other sites

C++ doesn't handle Pchar, Martin. If the Pascal is going to make a call to the dll, it will have to be in a form that the dll will understand.

Share this post


Link to post
Share on other sites

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.

Share this post


Link to post
Share on other sites

This question doesn't belong in this forum.

I cannot say why that would happen, have you tried with other window titles? Are you 100% sure the window is actually closed and not just hidden? Many programs will hide the window instead of destroy it so it can be loaded again later.

Share this post


Link to post
Share on other sites

#10 ·  Posted (edited)

Edit: Nevemind. You were right. It was a hidden window. :mellow:

Edited by Proph

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