Post below copied from Richard's post at groups.io - but the subsequent developments there render it probably less important, since it appears it works for most people, and/or most of the time. But if you develop a problem with this function, this may provide a solution!
Obviously this applies specifically to Windows.
Best wishes,
D
I have today noticed that BBC BASIC for Windows seems to have been broken by a recent Windows Update. Specifically, if your BASIC program calls the SetWindowLong API function in order to change the window style (many do), it may well now crash. I suspect the likely cause is that this API has, in the recent update, joined the set of functions that may only be called from the main (GUI) thread, whereas previously it could be called from any thread.
It is a weakness of Microsoft's Win32 API documentation that nowhere does it state which functions are thread-specific in this way and which are not, this can only be determined by trial-and-error. There has been no evidence, from Windows 95 up until quite recently, that SetWindowLong is fussy but now it appears to be, at least when changing the window style.
The only workaround that I am aware of, which is quite messy, is to temporarily subclass the GUI thread so that the call may be made from there (the same technique is used in WINLIB5 for calling the SetFocus API function):
DEF PROC_setwindowlong(H%,I%,S%)
LOCAL K%,M%,O%,P%
DIM P% LOCAL 48
[OPT 2
.K% push S% : push I% : push H% : call "SetWindowLong" : ret 16
.M% cmp dword [esp+8],&500 : jz K%
pop eax : push [^O%] : push eax : jmp "CallWindowProc"
]
SYS "GetWindowLong", @hwnd%, -4 TO O%
SYS "SetWindowLong", @hwnd%, -4, M%
SYS "SendMessage", @hwnd%, &500, 0, 0
SYS "SetWindowLong", @hwnd%, -4, O%
SYS "SendMessage", @hwnd%, 0, 0, 0
ENDPROC