Курсовая работа: Потоки в Visual Basic
Функция StartBackgroundThreadFree определена в модуле modMTBack следующим образом:
Declare Function CreateThread Lib "kernel32" _
(ByVal lpSecurityAttributes As Long, ByVal _
dwStackSize As Long, ByVal lpStartAddress As Long, _
ByVal lpParameter As Long, ByVal dwCreationFlags _
As Long, lpThreadId As Long) As Long
Declare Function CloseHandle Lib "kernel32" _
(ByVal hObject As Long) As Long
' Start the background thread for this object
' using the invalid free threading approach.
Public Function StartBackgroundThreadFree (ByVal qobj As clsBackground)
Dim threadid As Long
Dim hnd&
Dim threadparam As Long
' Free threaded approach
threadparam = ObjPtr(qobj)
hnd = CreateThread(0, 2000, AddressOf _
BackgroundFuncFree, threadparam, 0, threadid)
If hnd = 0 Then
' Return with zero (error)
Exit Function
End If
' We don't need the thread handle
CloseHandle hnd
StartBackgroundThreadFree = threadid
End Function
Функция CreateThread имеетшестьпараметров:
lpSecurityAttributes - обычно устанавливается в нуль, чтобы использовать заданные по умолчанию атрибуты защиты.
dwStackSize - размер стека. Каждый поток имеет собственный стек.