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