That's because the translation is incorrect. I don't have my code ready here, but this should come close:
- It needs to be a member of a TThread derived class
- You can't allocate nor define the record inside the procedure, it needs to be on the heap (global) and not on the stack (local) anyway
= You should use stdcall
- You should use PWideChar (the routine calls the widechar version anyway as per MSDN)
- You should copy in the Pwidechar, not assign the pointer.
AND this need SEH enabled for your complete FPC build (*everything* full fpc build, full library build) and I seem to remember I also protected the WideChar with a critical section, although that should not be necessary.
At least w/o being able to test this is much closer.
I'll give the proper code later.
First get this outside the procedure:
type
{$push}{align 8}
TThreadNameInfo = record
RecType: LongWord;
Name: PAnsiChar;
ThreadID: LongWord;
Flags: LongWord;
end;
{$pop}
Note it was not an easy task to get it to work.