Sign in to follow this  
Followers 0
creeping

How Do #include Files Work?

5 posts in this topic

I'm not to sure how the #include statement works in autoit.

When I program in C (see below) the code from the header file is inserted into the .exe file at compile time. Autoit does not seem to do this.

C source code example

#include <stdio.h>

int main(void)
{
    printf("hello");

    return 0;
}

Autoit source code example

#include <IE.au3>

$oIE = _IECreate()

Referring to the C code above, the stdio.h file would not need to be the the same directory as the running program file to access its functions.

Referring to the Autoit code above, the IE.au3 file would have to be the the same directory as the running program file to access its functions or it generates an error.

Right now the question, do I always have to put the header file in the same directory as the running program to access its functions, I know I could just copy the code from the header file into my program, but just wondering if there is a better way.

Thanks

Share this post


Link to post
Share on other sites



If you lookup #include in the help file it explains it in detail.



Get Beta versions Here Get latest SciTE editor Here AutoIt 1-2-3 by Valuater - A great starting point.

Time you enjoyed wasting is not wasted time ......T.S. Elliot
Suspense is worse than disappointment................Robert Burns
God help the man who won't help himself, because no-one else will...........My Grandmother

Share this post


Link to post
Share on other sites

Beta Helpfile include page

There is a special registry value that can be created at "HKEY_CURRENT_USER\Software\AutoIt v3\AutoIt" called "Include". It should be a REG_SZ (string) value. The contents of this value are a semi-colon delimited list of directories that should be searched for files when resolving #include's in addition to the standard locations.

Share this post


Link to post
Share on other sites

hmmm yea ok, thanks. Sounds funny, but I never thought of that as I assumed all #include files would work the same. :">

Share this post


Link to post
Share on other sites

#5 ·  Posted (edited)

I'm not to sure how the #include statement works in autoit.

When I program in C (see below) the code from the header file is inserted into the .exe file at compile time. Autoit does not seem to do this.

C source code example

#include <stdio.h>

int main(void)
{
    printf("hello");

    return 0;
}

Autoit source code example

#include <IE.au3>

$oIE = _IECreate()

Referring to the C code above, the stdio.h file would not need to be the the same directory as the running program file to access its functions.

Referring to the Autoit code above, the IE.au3 file would have to be the the same directory as the running program file to access its functions or it generates an error.

Right now the question, do I always have to put the header file in the same directory as the running program to access its functions, I know I could just copy the code from the header file into my program, but just wondering if there is a better way.

Thanks

The include file only need be available if you don't compile the script.

For a really informative experiment, code an AutoIT script with a simple "Hello, world!" GUI that uses one of the constants in #include<guiconstants.au3>, like $GUI_EVENT_CLOSE.

Compile the script, then decompile it an look at the resulting source. That explained a lot to me, including the importance of #include-once in your own include files.

My impression is "compile" is somewhat too strong a term for what AutoIT does. It's more like zipping the script text and the interpreter together, as described in the help file. Perl scripts can be packaged the same way by Perl2Exe.

:think:

P.S. Even better use an include file with lots of functions your current scipt doesn't need. An example:

#include<array.au3>
#Dim $Doubles[5]
For $n = 0 to 4
     $Doubles[$n] = $n * 2
Next
_ArrayDisplay("Doubles", $Doubles)

Compile that, then decompile it an look at the resulting script.

:(

Edited by PsaltyDS

Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law

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