Home > Software engineering >  CreateThread call parameters' lpParameter cannot pass
CreateThread call parameters' lpParameter cannot pass

Time:09-23

The top statement:
 Declare Function CreateThread Lib "kernel32" _ 
(lpThreadAttributes As Any, ByVal dwStackSize As Long, _
ByVal lpStartAddress As Long, ByVal lpParameter As Long, _
LpThreadId ByVal dwCreationFlags As Long, As Long) As Long
Dim Out3 As Long


Simple call:
 Sub Test1 () 
Dim the lp As Long, LLP As Long, As Long x
Lp=1000
X=CreateThread (Null, ByVal 0 & amp; The AddressOf z_pHandle OutText3, Varptr (lp), ByVal 0 & amp; , ThreadID1)
R=WaitForSingleObject (x, - 1)
The Debug. Print Out3 & amp; "!"
End Sub
Sub OutText3 (b As Long)
Out3=C * 2
End Sub


Lp values passed less than 1000 b, why?

CodePudding user response:

The lp is defined as a global variable to try again

CodePudding user response:

First this sb never believe upstairs.
The second
Sub OutText3 (b As Long)
Out3=C * 2
End Sub

B and out3 have relations?
Sub OutText3 (b As Long)
Out3=b * 2
End Sub

CodePudding user response:

Separately, and then under vb use CreateThread thread is not very stable, because most of the vb controls are not thread-safe
And multi-threaded debugging very trouble.
A collapse would soon end
I saw you again a bit code
You Sub Test1 () in the main thread calls the Debug. Print Out3 & amp; "!"
Nine times out of ten is not the correct output
The Debug. Print Out3 & amp; "!" You try to Out3=b * 2
Should be ok

CodePudding user response:

 Sub OutText3 As Long (b) 
Out3=C * 2
The Debug. Print Out3 & amp; "!"
End Sub

CodePudding user response:

reference aspower_ reply: 3/f
in addition, again under vb use CreateThread thread is not very stable, because most of the vb controls are not thread-safe
And multi-threaded debugging very trouble.
A collapse would soon end
I saw you again a bit code
You Sub Test1 () in the main thread calls the Debug. Print Out3 & amp; "!"
Nine times out of ten is not the correct output
The Debug. Print Out3 & amp; "!" You try to Out3=b * 2
It is ok to should

Is like that, I said my idea:
In the MSDN explain CreateThread lpParameter can pass parameters,
So I in Sub Test1 program, using CreateThread call Sub OutText3 (b As Long), and pass parameters lp to b,
Then waiting WaitForSingleObject OutText3 operation has been completed, Out3 should be 2 * the value of b, which is 2 * 1000.
But in practice, the lp parameters are passed less than Sub OutText3 (As Long) b to b, b is zero

CodePudding user response:

Why not use multiple processes?

CodePudding user response:

refer to 6th floor 4 teacher zhao response:
why not use multiple processes?
ha ha...

CodePudding user response:

 
Declare the Function CreateThread Lib "kernel32" _
(lpThreadAttributes As Any, ByVal dwStackSize As Long, _
ByVal lpStartAddress As Long, ByVal lpParameter As Long, _
ByVal dwCreationFlags As Long, byval lpThreadId As Long As Long)


Sub OutText3 ( byval
b As Long)Out3=C * 2
The Debug. Print Out3 & amp; "!"
End Sub

CodePudding user response:

Declare the Function CreateThread Lib "kernel32" _
(lpThreadAttributes As Any, ByVal dwStackSize As Long, _
ByVal lpStartAddress As Long, ByVal lpParameter As Long, _
ByVal dwCreationFlags As Long, & lt; Strong> Byval LpThreadId As Long As Long

CodePudding user response:

references 9 f PctGL response:
 
Declare the Function CreateThread Lib "kernel32" _
(lpThreadAttributes As Any, ByVal dwStackSize As Long, _
ByVal lpStartAddress As Long, ByVal lpParameter As Long, _
ByVal dwCreationFlags As Long, byval lpThreadId As Long As Long)


Sub OutText3 ( byval
b As Long)Out3=C * 2
The Debug. Print Out3 & amp; "!"
End Sub

Is as follows: the number of lp or not reach OutText3 b, public variables Out3 or=0
Sub OutText3 (byval b As Long)
Out3=b * 2
'the Debug. Print Out3 & amp; "!"
End Sub

CodePudding user response:

Before I wrong and correct results should be 2 building code
Sub OutText3 (byval b As Long)
Out3=b * 2
The Debug. Print Out3 & amp; "!"
End Sub
Put the c to b, if there is wrong, that is hell

CodePudding user response:

"Windows core programming"
  •  Tags:  
  • API
  • Related