I have a problem with this code .
'in module
Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)
Declare Function CreateThread Lib "kernel32" (lpThreadAttributes As Any, ByVal dwStackSize As Long, ByVal lpStartAddress As Long, lpParameter As Any, ByVal dwCreationFlags As Long, lpThreadID As Long) As Long
Declare Function CloseHandle Lib "kernel32" (ByVal hObject As Long) As Long
Public Sub Threadfunc()
dim i as integer
do until i = 20
form1.caption = i
sleep 500
i = i+1
loop
End Sub

'in form1
Private Sub Command1_Click()
Dim hThread As Long, hThreadID As Long
hThread = CreateThread(ByVal 0&, ByVal 0&, AddressOf threadfunc, ByVal 0&, ByVal 0&, hThreadID)
End Sub

When i run it in VB it works fine but when i run it as a compiled EXE un illegal operation in msvbvm60.dll occurs.
What's the problem?