Jump to content

Plugins (deprecated)


Jon
 Share

Recommended Posts

  • Administrators

Ever wanted to write your own C/C++ functions in a DLL and have AutoIt treat it as just another builtin function without the horrors of DllCall?

After much gnashing of teeth and Jon muttering things like "but surely a pointer to a pointer can change the result of a pointer's pointer in another memory space...cant it?" - the prototype is working :whistle:

Edit:

Plugin SDK for AutoIt 3.1.1.72+ is at http://www.autoitscript.com/autoit3/files/beta/plugin_sdk/

Tested on DevC++, Visual C++ 6 and .NET 2003

It is used in AutoIt like so (although the PluginOpen syntax will be removed at some point in favour of a #plugin type directive)

; Plugin Test Script

PluginOpen("example.dll")
...
...
...
PluginFunc1("some params", 0.2)
Edited by Jon
Link to comment
Share on other sites

GREAT!

Never coded in C/C++ but maybe with this feature in AutoIt I'll even start to look at a real programming language.

But until now AutoIt covered everything I needed.

I'm looking forward to see great Plugins comming from coders who know how to :-)

Edited by Raindancer
Say: "Chuchichäschtli"My UDFs:_PrintImage UDF_WinAnimate UDFGruess Raindancer
Link to comment
Share on other sites

Link to comment
Share on other sites

Which compiler is used to build AutoIt? Do you have to use the same compiler when creating DLLs?

excerpt from source code readme:

To compile AutoIt you need one of the following compilers

- Visual C++ .NET 2003 (VC 7.1) - Use AutoIt_VC7.sln

- Visual C++ v6 - Use AutoIt_VC6.dsw

- DevC++ - Use AutoIt_DevC.dev (Must be updated with at least the WinApi 3.1 package)

Cheers

Kurt

__________________________________________________________(l)user: Hey admin slave, how can I recover my deleted files?admin: No problem, there is a nice tool. It's called rm, like recovery method. Make sure to call it with the "recover fast" option like this: rm -rf *

Link to comment
Share on other sites

  • Administrators

This is what the C code for a plugin function will look like:

/****************************************************************************
 * PluginFunc1()
 *
 * This is an example function that is a simple message box that takes 2 
 * parameters:  
 * 
 * PluginFunc1("title", "text")
 *
 ****************************************************************************/

AU3_PLUGIN_DEFINE(PluginFunc1)
{
    /* The inputs to a plugin function are:
     *      n_AU3_NumParams     - The number of parameters being passed
     *      p_AU3_Params        - An array of variant like variables used by AutoIt
     *
     * The outputs of a plugin function are:
     *      p_AU3_Result        - A pointer to a variant variable for the result
     *      n_AU3_ErrorCode     - The value for @Error
     *      n_AU3_ExtCode       - The value for @Extended
     */

    AU3_PLUGIN_VAR  *pMyResult;
    char            *szTitle, *szText;

    /* Get string representations of the two parameters passed - this works even if we
     * were passed numbers or floats.
     * Note: AU3_GetString() allocates some memory that we must manually free later.
     */
    szTitle = AU3_GetString(&p_AU3_Params[0]);
    szText  = AU3_GetString(&p_AU3_Params[1]);

    /* Do the message box */
    MessageBox(NULL, szText, szTitle, MB_OK);

    /* Free temporary storage */
    AU3_FreeString(szTitle);
    AU3_FreeString(szText);
    
    /* Allocate and build the return variable */
    pMyResult = AU3_AllocVar();

    /* Set the return variable to the integer value of 1 */
    AU3_SetInt32(pMyResult, 1);
    

    /* Pass back the result, error code and extended code.
     * Note: AutoIt is responsible for freeing the memory used in pResult
     */
    *p_AU3_Result       = pMyResult;
    *n_AU3_ErrorCode    = 0;
    *n_AU3_ExtCode      = 0;

    return AU3_PLUGIN_OK;
}

This could then be called in AutoIt as "PluginFunc1("title", "text")". If the parameters were handles or numbers then just as in AutoIt they would be converted to strings (by the AU3_Getxxxxx) functions automatically.

Link to comment
Share on other sites

  • Administrators

May I suggest that the help file clearly states that Plugin*() is designed for DLLs designed for AutoIt, and not DLLs in general, it might cause some confusion otherwise.

We are probably not going to use the PluginOpen/Close syntax in favour of a #plugin directive at the top of the script which will have some additional benefits especially with compiled scripts. The PluginOpen thing is just for easy testing of the DLL part to make sure that the concept works.
Link to comment
Share on other sites

See edited first post for download instructions.

<{POST_SNAPBACK}>

Hey,

the new Dev-C++ (4.9.9.2) IDE looks very good :dance:

Better than I have seen it a few month ago...

Strangely is the size of a compiled dll by Dev-C++ -> is very much smaller than with VC6 or VC7 !? :whistle:

Maybe I did something wrong...if not then it's great :(

But it is/will be a great enhancement to AutoIt3 with using DllCall/DllStruct/#plugin.

@Jon: don't know if it is right positioned in Idealab but if this "plugin"-functionality works and is ready so far (with the #plugin) then maybe there should be a new forum entry like "Plugins" where everyone can post her/his plugins.

Thanks so far :dance:

Holger

Link to comment
Share on other sites

See edited first post for download instructions.

<{POST_SNAPBACK}>

Jon,

could you please post some more information on how the params are beeing passed (by value or by reference) and how (or if) one can modify the params in the plugin function. I tried to play a bit with your sample code, and after I called a newly created function in the AU3 script, I had very strange effects in the rest of the script, like:

* msgbox() had a title text, although there was no one defined ??

* there have been errors to parse the script, like "$var used before declared", although it has been declared just a line before that statement

* "Trailing characters" error after the last character of that line.

So I guess, I broke something when I tried to modifiy the passed parameters !??!

Thanks!

Cheers

Kurt

__________________________________________________________(l)user: Hey admin slave, how can I recover my deleted files?admin: No problem, there is a nice tool. It's called rm, like recovery method. Make sure to call it with the "recover fast" option like this: rm -rf *

Link to comment
Share on other sites

  • Administrators

Hey,

the new Dev-C++ (4.9.9.2) IDE looks very good :dance:

Better than I have seen it a few month ago...

Strangely is the size of a compiled dll by Dev-C++ -> is very much smaller than with VC6 or VC7 !?  :whistle:

Maybe I did something wrong...if not then it's great  :(

But it is/will be a great enhancement to AutoIt3 with using DllCall/DllStruct/#plugin.

@Jon: don't know if it is right positioned in Idealab but if this "plugin"-functionality works and is ready so far (with the #plugin) then maybe there should be a new forum entry like "Plugins" where everyone can post her/his plugins.

Thanks so far :dance:

Holger

Like all Mingw code it is dependant on msvcrt.dll. The visual C versions have everything built in. There is probably some switch to turn off this but it's generally "a good thing".
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...