Free Threading in VB
I''m trying to get some basic free multithreading into a VB app with some code that I know works in VB5.. VB6 acts very strangely when run in the IDE, and just GPFs when compiled. Here''s the gist of the code (the Init method from the CThread class):
Public Sub Initialize(ByVal lpfnBasFunc As Long)
Dim lStackSize As Long, lCreationFlags As Long, lpThreadId As Long, lNull As Long
On Error Resume Next
lNull = 0
lStackSize = 0
lCreationFlags = CREATE_SUSPENDED
uThread.Handle = CreateThread(lNull, lStackSize, lpfnBasFunc, lNull, lCreationFlags, lpThreadId)
If uThread.Handle = lNull Then
MsgBox "Create thread failed!"
End If
#If DEBUG_BUILD Then
AddLogEntry "Thread creation: " & uThread.Handle
#End If
End Sub
I call this method with:
Dim DPThread as new CThread
DPThread.Initialize (AddressOf DPLoop)
DPThread.Enabled = True '' PLet that resumes the thread
DPLoop is a method in a general module that contains a Do...Loop which checks for the availability of DirectPlay messages. It executes fine in the IDE (with some shaky thread exiting), but when I compile it, like I said, GPFville, thread never gets created.
Anyone have any clue?
Thanks,
Marc
SiliconReality Software
http://www.blackenfall.org
-Marc-SiliconReality Software-http://www.blackenfall.org
Race condition elsewhere in the code?
compiling would make it haul ass, compared to the interpretted code, so different behavior on compile suggests a timing issue, maybe...
Magmai Kai Holmlor
Mutex anyone?
compiling would make it haul ass, compared to the interpretted code, so different behavior on compile suggests a timing issue, maybe...
Magmai Kai Holmlor
Mutex anyone?
- The trade-off between price and quality does not exist in Japan. Rather, the idea that high quality brings on cost reduction is widely accepted.-- Tajima & Matsubara
Visual Basic 6 does not allow you to create threads. It was sort of ok for VB5 (if you''re careful), but Microsoft have stopped it now.
MS''s VB people are such nice guys.. "Hey, we don''t think they should use this feature in their apps. Let''s totally disallow them from doing it." Heh, oh well, there''s always apartment threading until VB.NET arrives..
Marc
SiliconReality Software
http://www.blackenfall.org
Marc
SiliconReality Software
http://www.blackenfall.org
-Marc-SiliconReality Software-http://www.blackenfall.org
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement
Recommended Tutorials
Advertisement