The future depends on us. It is up to us to the future of Clarion.
Will this programming language to live long and happy life or dies in oblivion depends on us. If you have to say, do it here in this blog. Welcome!

Read More

Windows Threads

Today 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: | No Comments »

Category: General

Leave a Reply

This is a captcha-picture. It is used to prevent mass-access by robots. (see: www.captcha.net)

You must read and type the 5 chars within 0..9 and A..F, and submit the form.

  

Oh no, I cannot read this. Please, generate a