Что нового

Функция создания потока( _ThreadCreate)

Arei

Скриптер
Сообщения
938
Репутация
115
вот функция создания потока,как с ней работать?

Код:
; ===================================================================================================================
; Func _ThreadCreate($pFuncPtr,$vParam=0,$bCreateSuspended=False)
;
; Creates a Thread in the current process. The function pointer must point to code to execute.
;	In AutoIt, this must be done by allocating memory (using VirtualAlloc or GlobalAlloc+VirtualProtect) and
;	writing to it using DLLStruct*() functions.
;
; $pFuncPtr = pointer to buffer where Thread to execute is located at
; $vParam = Parameter to pass to Thread (only 1 is allowed) [32-bit on x86, 64-bit on x64]
; $bCreateSuspended = If True, create the Thread and put it in a suspended state immediately.
;					If False, it will execute immediately.
; $iStackSize = stack size to allocate to Thread (0 = allocate default stack)
;	* If set to a value thats <2048 (-1 for example), the function uses the default $_THREAD_DEFAULT_STACK_SIZE)
;
; Returns:
;	Success: Thread Handle, and @extended = Thread ID
;	Failure: 0, with @error set:
;		@error = 1 = invalid parameter
;		@error = 2 = DLLCall error, @extended = DLLCall @error code (see AutoIT help)
;		@error = 3 = 0 Returned from API call (failure - call GetLastError for info)
;
; Author: Ascend4nt
; ===================================================================================================================

Func _ThreadCreate($pFuncPtr,$vParam=0,$bCreateSuspended=False,$iStackSize=0)
	If Not IsPtr($pFuncPtr) Then Return SetError(1,0,0)
	Local $iAttrib
	If $bCreateSuspended Then
		$iAttrib=4	; CREATE_SUSPENDED = 4
	Else
		$iAttrib=0	; thread starts immediately
	EndIf

	If $iStackSize And $iStackSize<2048 Then $iStackSize=$_THREAD_DEFAULT_STACK_SIZE

	Local $aRet=DllCall($_COMMON_KERNEL32DLL,"handle","CreateThread","ptr",0, _
		"ulong_ptr",$iStackSize,"ptr",$pFuncPtr,"ulong_ptr",$vParam,"dword",$iAttrib,"dword*",0)

	If @error Then Return SetError(2,@error,0)
	If Not $aRet[0] Then Return SetError(3,0,0)
	$THREAD_LAST_TID=$aRet[6]
;~ 	ConsoleWrite("Thread created successfully, handle="&$aRet[0]&", Thread ID="&$aRet[6]&", CreatedSuspended="&$bCreateSuspended&@CRLF)
	Return SetError(0,$aRet[6],$aRet[0])
EndFunc

Помогите разобраться.


Добавлено:
Сообщение автоматически объединено:

Функция взята с http://www.autoitscript.com/forum/topic/115352-process-thread-dll-functions-udfs/page__hl___threadcreate
 

kaster

Мой Аватар, он лучший самый
Команда форума
Глобальный модератор
Сообщения
4,020
Репутация
626
это та же функция что в этой теме?
http://autoit-script.ru/index.php/topic,6322.msg52007/topicseen.html#new
 
Автор
A

Arei

Скриптер
Сообщения
938
Репутация
115
Да, но там много не нужного, решил создать новую.
 
Верх