It seems that the Windows machine needs to be joined to a Windows domain for this call to return something sensible.
That's... weird, because it doesn't seem to be the case with my Windows installations, nor do Microsoft's docs specify this. (See [https://learn.microsoft.com/en-us/windows/win32/api/secext/nf-secext-getuser...))
Do you have an application that depends [on] this?
Yes, I do. It's a game modification called "[OneShot: Fading Memory](https://store.steampowered.com/app/1569440/OneShot_Fading_Memory/)", which I am one of the developers of. It has been released two years ago and has always relied on the GetUserNameEx method. We've received no bug reports related to the game querying the player's name.