Sign in to follow this  
Followers 0
imNew

How to use AutoIt in C++?

5 posts in this topic

Hi Everybody, how is it going.

The title is very general, sorry about that. I am fairly new to C++, only thing about files or libraries I can understand is "#include".

however I insist on using c++, so that I can learn a ubiquitous language and still have the awesomeness of autoit with me.

When I google my question, I am getting outdated advice about adding non-existent files into a C++ project. The only information I can extract out of this forum is that I have to "dynamically link" something.

and I tried that, doesn't work, can't even get Sleep(1000) to work

#include <Windows.h>

#include "AutoIt3.h"

int APIENTRY WinMain(HINSTANCE hInstance,

HINSTANCE hPrevInstance,

LPSTR lpCmdLine,

int nCmdShow)

{

HINSTANCE hGetProcIDDLL = LoadLibrary("C:\\Users\\User\\Desktop\\C++Projects\\AutoItX3.dll");

FARPROC lpfnGetProcessID = GetProcAddress(HMODULE (hGetProcIDDLL),"AU3_Sleep()");

typedef int (__stdcall * pICFUNC)(char *, int);

pICFUNC MyFunction;

MyFunction = pICFUNC(lpfnGetProcessID);

MyFunction(1000);

FreeLibrary(hGetProcIDDLL);

return 0;

}

Could someone patient enough give us new comers a step to step instruction just how to use AutoIt in c++, we only have header and dll files.

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

I use AutoIt from C++, like this:

system("..scriptsscript.exe");

I transfer values with a file read or written to from both AutoIt and C++ application.

What you are doing is a better scope, but beyond mine.

Edited by Xandy

Share this post


Link to post
Share on other sites

Your code is all over the place and wrong. Your types make no sense. I'll correct it and post it but you really have a lot to learn before trying this.

#include <Windows.h>
#include "AutoIt3.h"

typedef void (__stdcall *pAU3_Sleep)(long);

int APIENTRY WinMain(HINSTANCE hInstance,
                     HINSTANCE hPrevInstance,
                     LPSTR   lpCmdLine,
                     int       nCmdShow)
{
    HMODULE dllHandle = LoadLibrary("AutoItX3.dll");
    
    pAU3_Sleep funcHandle = (pAU3_Sleep)GetProcAddress(dllHandle, "AU3_Sleep");
    
    funcHandle(1000);
    
    FreeLibrary(dllHandle);
    return 0;
}

Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

thank you, thank you both,

with any bits or pieces of code, as long as they work.

upside down 's code is really helpful, declare a pointer (I guess the pointer can only point to autoit functions take "long"s), load the dll, point the pointer to the autoit function and start using. that actually makes lots of sense now.

Anything else I should be aware of for using autoit in c++?

thanks in advance

Edited by imNew

Share this post


Link to post
Share on other sites

My name is Richard. The upside down thing was a joke.

The pAU3_Sleep pointer will actually work for any function that returns void and takes a long parameter. I don't think there are any others though.

You need to exactly match the types of the parameters and return value until you absolutely know the consequences of changing them.

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