Windows Threads
Posted May 19th, 2009 by Andrew PopoffToday I tried to create a thread using Windows API. I always thought that there are no problems. But it turned out that I can not do anything. I can not even use the MESSAGE in the thread procedure. The application always crashes.
Below is the code that creates a new thread and simply increases the value of a variable. It works.
PROGRAM
MAP
MODULE('WinAPI')
CreateThread(LONG,LONG,LONG,LONG,LONG,LONG),ULONG,PASCAL,NAME('CreateThread')
memcpy(LONG,LONG,LONG),LONG,RAW,NAME('_memcpy'),PROC
END
TThreadProc(LONG lpParameter),PASCAL
END
Window WINDOW('Caption'),AT(,,129,115),FONT('MS Sans Serif',8,,FONT:regular),GRAY
BUTTON('Start thread'),AT(4,4,81,18),USE(?OkButton),DEFAULT
BUTTON('Show results'),AT(4,30,81,18),USE(?CancelButton)
END
ThreadID LONG
Param LONG
hThread ULONG
CODE
OPEN(Window)
DISPLAY
ACCEPT
CASE ACCEPTED()
OF ?OkButton
hThread = CreateThread(0,0,ADDRESS(TThreadProc),ADDRESS(Param),0,0)
MESSAGE('Thread handle: ' & hThread)
OF ?CancelButton
MESSAGE('Param: ' & Param)
END
END
TThreadProc PROCEDURE(LONG lpParameter)
loc:Var LONG
CODE
! MESSAGE('Enter TThreadProc') crashed
LOOP
loc:Var += 1
memcpy(lpParameter,ADDRESS(loc:Var),4)
END
Tags: Windows threads | No Comments »
Leave a Reply