how send parameters on CreateThread()?
on a class:

Option Explicit

Private 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
Private Declare Function TerminateThread Lib "kernel32" (ByVal hThread As Long, ByVal dwExitCode As Long) As Long
Private Declare Function CloseHandle Lib "kernel32" (ByVal hObject As Long) As Long

Private hThreadID As Long
Private hThread As Long

Public Sub Execute(FunctionName As Long, Optional parameters As Long = 0)
     hThread = CreateThread(ByVal 0&, 0&, FunctionName, ByVal parameters, 0&, hThreadID)
End Sub

on module:

Option Explicit

Public Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" (Destination As Any, Source As Any, ByVal Length As Long)



Public Sub Test(parameters As Long)
    Dim s As String
    CopyMemory s, ByVal parameters, Len(parameters)
    Debug.Print s
End Sub

on form1:

Option Explicit

Dim s As Multithread

Private Sub Command1_Click()
     Set s = New Multithread
     Dim nome As String
     nome = "Joaquim"
     s.Execute AddressOf Test, StrPtr(nome)
End Sub

my problem is how i send parameters on CreateThread() function and get it.

While I see the discussion at https://www.vbforums.com/showthread.php?902072-how-use-CreateThread()-with-parameters appears to have solved this I will share an old workaround I used decades ago.

It was decades ago and the API was limited so I put the parameters into a file that the new thread would read and act on. It worked and as such never had to solve this on, at the time Windows 3.1. Sometime in early 2000 another OS and limitation so I did that again. Better to meet delivery dates than fret about a bodge.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.