Jump to content

Inline C Source In AutoIt


Ward
 Share

Recommended Posts

Is it possible to use also AutoIt function within C code?

  • Use DLLCallBackRegister to get a pointer of the AutoIt Func
  • Pass the pointer into C code as a parameter
  • Write C code that get the "function pointer" as a parameter, and it can be use in the code
Example may be in next release.

新版 _ArrayAdd 的白痴作者,不管是誰,去死一死好了

 

Link to comment
Share on other sites

Link to comment
Share on other sites

I'm creating examples, but I wonder if the licence applied to headers, since I've extracted functions from windows sdk.

I've created an example for sorting a listview, I'll publish if licence is ok.

-- Arck System _ Soon -- Ideas make everything

"La critique est facile, l'art est difficile"

Projects :

[list] [*]Au3Service : Run your exe as service V3 / Updated 29/07/2013 Get it Here [/list]
Link to comment
Share on other sites

It can be VERY handy. Sorting listviews is very useful usage.

I hope licence will be OK.

sorting listview with guictrlregisterlistviewsort = around 10 sec for 5000 items with 3 columns.

In C : 70 ms ....

I hope so ...

TCC doesn't like sdk headers for this code, so i've adapted it with MinGW listview function headers but still, I have to know if I can extract them.

-- Arck System _ Soon -- Ideas make everything

"La critique est facile, l'art est difficile"

Projects :

[list] [*]Au3Service : Run your exe as service V3 / Updated 29/07/2013 Get it Here [/list]
Link to comment
Share on other sites

I have question: in Example2.au3

...
    TCC_Add_Include_Path($TCC, @ScriptDir & "\include")
    TCC_Add_Include_Path($TCC, @ScriptDir & "\include\winapi")
    TCC_Add_Library_Path($TCC, @ScriptDir & "\lib")
    TCC_Add_Library($TCC, "user32")
    ...

Does it mean I need to distribute these folders with my compiled EXE?

If answer is Yes then another question: Can be used these files (ideally only used ones) from resources?

(add all neccessary files to resources at compile time and use them from variables at runtime)

Edited by Zedna
Link to comment
Share on other sites

Does it mean I need to distribute these folders with my compiled EXE?

If answer is Yes then another question: Can be used these files (ideally only used ones) from resources?

(add all neccessary files to resources at compile time and use them from variables at runtime)

The answer is YES.

I will add some example for "Binary Code Generator" later.

Then the distribute version can only include the binary code. Not need entire TCC library.

新版 _ArrayAdd 的白痴作者,不管是誰,去死一死好了

 

Link to comment
Share on other sites

Another question:

Can be used inline C code in some precompiled form?

Once before compilation of main AU3 script in some helper AU3 script should be precompiled and saved C code into binary file.

Then in main AU3 script this precompiled binary C code could be added to resources and only called (not compile at runtime).

EDIT:

I will add some example for "Binary Code Generator" later.

We had the same idea at the same time :-) Edited by Zedna
Link to comment
Share on other sites

Another question:

Is it possible to pass array as parameter from AU3 to C?

_ArrayToString() is the ideal adept for such C optimizing.

So my idea is to create C function ArrayToString() with parameters: Array, Delim, Start, End

and call it directly from AU3 and pass Autoit's array directly (maybe with ByRef as pointer?).

For $i = $iStart To $iEnd
   $sResult &= $avArray[$i] & $sDelim
Next
Edited by Zedna
Link to comment
Share on other sites

With LibTCC, we can add some C source to speed up the time-consuming subroutines.

I looked at some of my projects and I have these generally used adepts for translating from AU3 to C for speed optimize:

1) ArraySort()

2) _ArrayToString()

For $i = $iStart To $iEnd
        $sResult &= $avArray[$i] & $sDelim
Next

3) FindInArray()

For $i = 1 to $avArray[0]
        If $avArray[$i] = $what Then Return $i
Next
Return 0

4) _StringRepeat()

For $iCount = 1 To $iRepeatCount
        $sResult &= $sString
Next

5) ListViewGetItemText(), ListViewGetSubItemText()

6) ListViewToText()

For $i = 0 To _GUICtrlListView_GetItemCount($ListView1) - 1
        $txt &= _GUICtrlListView_GetItemTextString($ListView1, $i) & $sDelim
Next

7 ) _ArrayToXLS(), __XLSWriteCell()

Edited by Zedna
Link to comment
Share on other sites

@Ward :

I've some examples but I've extracted some functions from headers from MinGW.

I need to know if I can post it just with headers needed (windows.h)

I'll post it anyway and if there is a licence problem, then i'll remove it.

-- Arck System _ Soon -- Ideas make everything

"La critique est facile, l'art est difficile"

Projects :

[list] [*]Au3Service : Run your exe as service V3 / Updated 29/07/2013 Get it Here [/list]
Link to comment
Share on other sites

@Ward :

I've some examples but I've extracted some functions from headers from MinGW.

I need to know if I can post it just with headers needed (windows.h)

I'll post it anyway and if there is a licence problem, then i'll remove it.

I think of course you can post it.

MinGW is open source and anyone can download it.

I don't see any licence problem here.

I am waiting to see your example :mellow:

新版 _ArrayAdd 的白痴作者,不管是誰,去死一死好了

 

Link to comment
Share on other sites

So, after one day of rework, and a week to understand some lack in C for me, here is my example. You need to download and merger the include from MinGW ( this code doesn't work with windows.h from windows sdk, at least for me ! )

The function to sort dates doesn't work for now since TCC doesn't like msdn c++ style.

The code itself is inspired by an example from sysinternal accessenum, which contains a file listview.cpp, which contains all the need for a cleaner and a complete code since

we can sort float, dates, strings, and hex.

here it is Listview.cpp from accessenum

the autoit part has been disabled, but you can reactivate the function "testautoit" to see the difference.

copy with other examples

Example5Lite.au3

same for it

ListViewSortLite.c

Edited by arcker

-- Arck System _ Soon -- Ideas make everything

"La critique est facile, l'art est difficile"

Projects :

[list] [*]Au3Service : Run your exe as service V3 / Updated 29/07/2013 Get it Here [/list]
Link to comment
Share on other sites

  • 2 weeks later...

Ward,

All this fun Ive been having with TCC I decided to set up a standalone IDE with Scite just for TCC. This way I can write, test, and spot out any syntax errors I might have added. Any time I have a syntax error, just like Scite for autoit does, I can click on the error in the console and Scite takes me right to the line. Also making it standalone lets me have both IDE's open with out effecting each other.

I tried to make it as much like the way autoit has Scite set up as I could. Its got an api set up for Calltips, Autocomplete list pops up when a possible choice is there. F5 will run, F7 or Shift-F7 will compile an exe in the same directory as the source. To set the parameters for command line arguments like in example fib.c, go to View->Parameters or just press Shift-F8. I also added a little tool to create a AU3 string from the C code. Its in the editors right-click menu and also in the tools menu.

The lexer used is a Lua LPeg lexer. A dynamic lexer I never knew existed until doing this. The color settings for this lexer are a little different than standard Scite lexers. Instead of being in a .properties file they are in a theme file located in LPEG_Lexer\Themes. The colors I have currently set up are for a dark background so im sure people will want to change them to the way they like it. :mellow:

SciteTCC.html

Link to comment
Share on other sites

  • 11 years later...

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...