1. It should also work with older FPC versions (read 3.0.4) if you do the typecast PascalDragon mentioned.
2. The console output just gives some extra infos but the threadnames can only be seen in a debugger which supports threadnames by MS_VC_EXCEPTION. I've used x64dbg as debugger to verify the method for older Windows on my Win10 system.
3. You need at least gdb 8.0 or newer as mentioned before. Older versions doesn't support the exception type from point 2)
4. Not sure what Lazarus shows in its thread window but normally it shouldn't support it (at least not through gdb with your version)
5. It's a PoC so I didn't really paid attention if everything is freed correctly.
1. Oddly enough, I check and you don't. Not compiled in 3.0.4. without Windows.
2. Cast will not help, THandle is 64 bit, but the parameter is DWORD. I checked - the value is really more than 32 bits.
3. I only use the debugger that comes with the latest official version of Lazarus. And of course, in the context of the Lazarus forum, it is unusual to discuss that this is not appropriate for it.
4. The heap trace shows that the release is incorrect.
5. Under the debugger, the program does not work at all.