Jump to content
Sign in to follow this  
FredAI

Multi-thread AutoIt

Recommended Posts

Well, my first goal was to make it be able to call AutoIt functions, so we can run AutoIt code in a different thread.

I tried passsing a pointer to a DllCallback function, but for some reason the program always crashed.

I still have a few ideas I'm gonna try today. If I make some progress, I'll post here.

Share this post


Link to post
Share on other sites

It's comments like this one that keep me away from the forums.

Did you even take a look at the code?

Didn't you see that the DLL is creating each message box in a different thread by calling CreateThread?

Didn't you see the message boxes being closed each time TerminateThread is called?

Isn't that multi-threading?

Work first. Comment later.

I didn't mean to hurt you my friend, I just want to say that your topic is miss leading.

Everyone know that it's not impossible to create a thread in AutoIT with other methods like ASM and external DLLs so my point is this is not a new concept, As Andreik wrote, If anyone have to write "complicated parts" in C, it is better to write entire app in C.

The example your demonstrating is quite easy to create even without creating any external DLL.

I am sorry if my comment hurt you.


73 108 111 118 101 65 117 116 111 105 116

Share this post


Link to post
Share on other sites

No prob, but let me tell you that you're wrong. The exampe proves that it's possible to create and run as many threads as you want, but only running those threads in an exteral dll's function body. If you try passing a pointer to a DllCalback function your program will crash.

Believe me, I tried it. :mellow:

Now what doesn't seem possible is to run autoit code within the new threads. I think it's related to the variables scopes.

I'm still trying, though. I already managed to make it work, but only for one Window (created with AutoIt code in a new thread). But when I try to create another one... crash.

My bad. Maybe I'll make it work?

Share this post


Link to post
Share on other sites

It's pretty tricky working witth the callbacks, I was playing with them and winhttp, always crashes if there's more than 1 and it gets called at the same time.

Share this post


Link to post
Share on other sites

No prob, but let me tell you that you're wrong.

Where I am wrong my friend ?

The exampe proves that it's possible to create and run as many threads as you want, but only running those threads in an exteral dll's function body.

I already admit it is possible, but I am pointing that people will not like the idea to create external dll; other proved approach is ASM which also a headache. You can find several examples, specially from trancexx.

If you try passing a pointer to a DllCalback function your program will crash.

Not in case if you are creating a thread with hard coded ASM. Believe me I tried it, I created an ASM thread to lock any plugged USB drive, I used global DllStruct and some DllCallbacks.

Now what doesn't seem possible is to run autoit code within the new threads. I think it's related to the variables scopes.

I'm still trying, though. I already managed to make it work, but only for one Window (created with AutoIt code in a new thread). But when I try to create another one... crash.

Not only related to variables scopes, AutoIt is not thread-safe language. Only possibility is re-write the AutoIt core interpreter, and it is impossible for now.

If you find some way to make it work, this will be awesome, so keep it up my friend.


73 108 111 118 101 65 117 116 111 105 116

Share this post


Link to post
Share on other sites

I just said you were wrong beacause you said it was not possible and that you can do the same thing with AutoIt code. It's not true and the example proves it. If you can come up with an autoIt script that does the same as my example it will be cool.

You say "Complicated C code". That depends on whether you know how to program in C/C++ or not.

Take a look at the code I used to draw the scrolling parts of the desktop in the two small windows. Of course, it's possible to do the same thing in autoIt, but it woud be much more complicated and need much more lines of code.

I just said an external dll can help to make many things possible, and multithreading is one of them. I'm not forcing anyone to use it, Those who want to stick to ONLY AutoIt code, can simply ignore the topic.

Share this post


Link to post
Share on other sites

I just said you were wrong beacause you said it was not possible and that you can do the same thing with AutoIt code. It's not true and the example proves it. If you can come up with an autoIt script that does the same as my example it will be cool.

You say "Complicated C code". That depends on whether you know how to program in C/C++ or not.

Take a look at the code I used to draw the scrolling parts of the desktop in the two small windows. Of course, it's possible to do the same thing in autoIt, but it woud be much more complicated and need much more lines of code.

I just said an external dll can help to make many things possible, and multithreading is one of them. I'm not forcing anyone to use it, Those who want to stick to ONLY AutoIt code, can simply ignore the topic.

You totally ignore what i said, anyway best of luck my friend.

73 108 111 118 101 65 117 116 111 105 116

Share this post


Link to post
Share on other sites

Could you show me how to accept a structure pointer in this?

I want to pass multiple variables, like a string, a float, int, dword and what not and read them on the DLL side, I've already made something with this, but I just need to know more of the basics to get anywhere else...

Also, thanks a LOT for this, you don't know how much this helped me, I was looking for just such an example when you posted this because I figured it would make something I'm doing much faster.

Share this post


Link to post
Share on other sites

Ok, figured it out already.

DWORD WINAPI _ThreadProc(LPVOID threadData)

{

struct THREAD_PARAM_COMPONENTS *tData = (struct THREAD_PARAM_COMPONENTS *)threadData;

Share this post


Link to post
Share on other sites

Well, I'm glad the example is helping you. I had started to answer with an example, but you were faster.

I don't know how you're declaring THREAD_PARAM_COMPONENTS, but here goes an example:

Declare your struct at the top of the file, preferently.

typedef struct ThreadProc1Data {LPWSTR text;float myfloat;int myint;DWORD mydword;} *PThreadProc1Data;

Then your function:

DWORD WINAPI _ThreadProc1(LPVOID param)
{
   PThreadProc1Data pth4d = (PThreadProc1Data)param;
   //Your thread code
} // End of _ThreadProc1

Then your autoIt code:

Local $sText = DllStructCreate('wchar[300]')
DllStructSetData($sText,1,'This is the string to pass to the DLL''s thread function.')
Local $sThread1 = DllStructCreate('ptr text;float myfloat;int myint;DWORD mydword')
DllStructSetData($sThread1,'text',DllStructGetPtr($sText,1))
Local $aThread1 = _AutoItThreadCreate(1,DllStructGetPtr($sThread1))

Note: not tested:

Hope it helps.

Fred

Edited by FredAI

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  

  • Recently Browsing   0 members

    No registered users viewing this page.

×
×
  • Create New...