Jump to content

CreateThread , need some help


Recommended Posts

ok i wantet to create a new thread for multithreading, but it wont work, it always failes at the CreateRemoteThread :

Func NewThread( $Func )

    Local $modHandle, $LoadLibraryA, $hThread
    
;open dll that we'll be using
    Local $kernel32 = DllOpen("kernel32.dll")
    $modHandle = DllCall($kernel32, "long", "GetModuleHandle", "str", "kernel32.dll")
    If IsArray($modHandle) Then
        If $modHandle[0] > 0 Then
            $modHandle = $modHandle[0]
        Else
            SetError(-1)
            Return False
        EndIf
    Else
        SetError(-2)
        Return False
    EndIf
    $LoadLibraryA = DllCall($kernel32, "long", "GetProcAddress", "long", $modHandle, "str", "LoadLibraryA")
    If IsArray($LoadLibraryA) Then
        If $LoadLibraryA[0] > 0 Then
            $LoadLibraryA = $LoadLibraryA[0]
        Else
            SetError(-3)
            Return False
        EndIf
    Else
        SetError (-4)
        Return False
    EndIf
    $hThread = DllCall($kernel32, "int", "CreateRemoteThread", "int", @AutoItPID, "int", 0, "int", 0, "long", $LoadLibraryA, "long", $Func, "int", 0, "int", 0)
    If IsArray($hThread) Then
        ConsoleWrite($hThread[0] & @CR)
        If $hThread[0] > 0 Then
            $hThread = $hThread[0]
        Else
            SetError(-5)
            Return False
        EndIf
    Else
        SetError(-6)
        Return False
    EndIf

;DllCall($kernel32, "int", "VirtualFreeEx", "int", $pHandle, "int", $pLibRemote, "int", 0x1000, "int", 0x8000)
    DllCall($kernel32, "int", "CloseHandle", "int", $hThread)
;DllCall($kernel32, "int", "CloseHandle", "int", $pHandle)
    
    DllClose($kernel32)

EndFunc
My UDF's : Startet on : 06.06.2006_CaseSearchOrReplaceStr();~> Searches OR Replaces a String,;~> With or Without Casesensivity
Link to comment
Share on other sites

hmm :(

dont know, i cant really call dlls, i only used some of the code and wantet to make them working, but its not easy as in my brain :)

and i wantet to call it like this :

$thread = NewThread( "test" )
MsgBox( 0,"", "@error: " & @error & @CRLF & "return: " & $thread )

Func test()
    MsgBox(0,"","test has been running")
EndFunc
Edited by Busti
My UDF's : Startet on : 06.06.2006_CaseSearchOrReplaceStr();~> Searches OR Replaces a String,;~> With or Without Casesensivity
Link to comment
Share on other sites

maby if i had a week off :)

you need to figure out where autoits parser func(s) is/(are) located in the memory then create a thread at that location.

then you need to find a way to make it parse & execute your function.

Edited by w0uter

My UDF's:;mem stuff_Mem;ftp stuff_FTP ( OLD );inet stuff_INetGetSource ( OLD )_INetGetImage _INetBrowse ( Collection )_EncodeUrl_NetStat_Google;random stuff_iPixelSearch_DiceRoll

Link to comment
Share on other sites

maby if i had a week off :)

you need to figure out where autoits parser func(s) is/(are) located in the memory then create a thread at that location.

then you need to find a way to make it parse & execute your function.

cant it be done like in c++ with CreateThread ( "function" )

?

My UDF's : Startet on : 06.06.2006_CaseSearchOrReplaceStr();~> Searches OR Replaces a String,;~> With or Without Casesensivity
Link to comment
Share on other sites

More than once. I love that udf

My Programs:AInstall - Create a standalone installer for your programUnit Converter - Converts Length, Area, Volume, Weight, Temperature and Pressure to different unitsBinary Clock - Hours, minutes and seconds have 10 columns each to display timeAutoIt Editor - Code Editor with Syntax Highlighting.Laserix Editor & Player - Create, Edit and Play Laserix LevelsLyric Syncer - Create and use Synchronised Lyrics.Connect 4 - 2 Player Connect 4 Game (Local or Online!, Formatted Chat!!)MD5, SHA-1, SHA-256, Tiger and Whirlpool Hash Finder - Dictionary and Brute Force FindCool Text Client - Create Rendered ImageMy UDF's:GUI Enhance - Enhance your GUIs visually.IDEA File Encryption - Encrypt and decrypt files easily! File Rename - Rename files easilyRC4 Text Encryption - Encrypt text using the RC4 AlgorithmPrime Number - Check if a number is primeString Remove - remove lots of strings at onceProgress Bar - made easySound UDF - Play, Pause, Resume, Seek and Stop.
Link to comment
Share on other sites

can you use it too if autoit is NOT installed ?

and wouter, can you try it with createthread ? would be n1 :)

Yes, it works with compiled scripts on computers that don't have AutoIt installed.

[u]My UDFs[/u]Coroutine Multithreading UDF LibraryStringRegExp GuideRandom EncryptorArrayToDisplayString"The Brain, expecting disaster, fails to find the obvious solution." -- neogia

Link to comment
Share on other sites

yep its nice, but i think it doesnt work like i want^^

I think @w0uter is pulling your leg because you have not done a proper search in the forum. If you did you would find that AutoIt does not support multi threading. Your best bet, AutoIt only, is @neogia's CoRoutine udf.

I don't remember if @neogia's samples include bundeling the files in one package (search for fileinstall and AutoIt3ExecuteScript )

Link to comment
Share on other sites

I think @w0uter is pulling your leg because you have not done a proper search in the forum. If you did you would find that AutoIt does not support multi threading. Your best bet, AutoIt only, is @neogia's CoRoutine udf.

I don't remember if @neogia's samples include bundeling the files in one package (search for fileinstall and AutoIt3ExecuteScript )

didnt you read wouters post ?

he wrote if he spent about 1-2 weeks he could find a way...

so i think you must learn read

maby if i had a week off tongue.gif

you need to figure out where autoits parser func(s) is/(are) located in the memory then create a thread at that location.

then you need to find a way to make it parse & execute your function.

Edited by Busti
My UDF's : Startet on : 06.06.2006_CaseSearchOrReplaceStr();~> Searches OR Replaces a String,;~> With or Without Casesensivity
Link to comment
Share on other sites

I think @w0uter is pulling your leg because you have not done a proper search in the forum. If you did you would find that AutoIt does not support multi threading. Your best bet, AutoIt only, is @neogia's CoRoutine udf.

I don't remember if @neogia's samples include bundeling the files in one package (search for fileinstall and AutoIt3ExecuteScript )

Actually, with my UDF, there's no need to fileinstall anything, it handles everything dynamically. All you must do is supply the code.

[u]My UDFs[/u]Coroutine Multithreading UDF LibraryStringRegExp GuideRandom EncryptorArrayToDisplayString"The Brain, expecting disaster, fails to find the obvious solution." -- neogia

Link to comment
Share on other sites

You know the expression "pulling your leg"? Like "making a joke on your behafe"? I'm sorry, I might have to learn to read, but you probably have to learn how to use this search link :(

....

AutoIt can do multiple things at the same time by running multiple scripts. That isnt an issue.

AutoIt being based on C++ is similiar to it in architecture. It is a top down language. Granted you can call functions and they will execute their code, but unlike C++ it doesnt have threading support. Maybe you could list this in the Ideas forum. For all I know someone is trying to currently implement it. I know enough C++ to get done with my Encryption project not much more. I am using my project to push me to learn more about that area of C++.

...

If this information was outdated I think you would find it in the help file or by searching for +CreateThread +dllcall.

As you can see from my signature I have found a solution suiting my needs. @negoia has provided a process solution. And @w0uter has provided part of a solution through his mem functions.

But by all means, you might find a solution on how to use functions in a separate thread. If you do make sure to post it, you will make a lot of people happy :)

Edited by Uten
Link to comment
Share on other sites

I figured this thread would die out so I've refrained from posting. However, since it's not dying, I guess I should respond.

AutoIt is not thread-safe. Even if you do manage to get CreateThread() running AutoIt code, you're just going to crash AutoIt. AutoIt was designed to be single-threaded. All those really important invariants we make based on that fact will be broken if a second thread gets turned loose outside of our control inside of our engine. At the very least, if the numerous race conditions manage to run side by side without crashing AutoIt, function arguments will be completely wrong. Getting AutoIt code to execute via CreateThread() is not only completely pointless, it's completely unstable.

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