Maybe I misunderstood your question. I read it as you wanted to determine the screen orientation first (while the screen is still free to rotate) and then you would freeze it using SetScreenOrientation. The code I left will tell you the orientation; frozen or free to rotate.
Thanks, both of you. But I think there is no solution. Either I set the orientation, then it is fixed no matter how the device is held. Or I don't, then I can get the orientation.
Thank you, that would work! But my security app warns me that this app could be harmful and should be deinstalled. So I will leave the problem for now.