From https://learn.microsoft.com/en-us/windows/win32/direct3ddxgi/desktop-dup-api
Rotating the desktop image
You must add explicit code to your desktop duplication client app to support rotated modes. In a rotated mode, the surface that you receive from IDXGIOutputDuplication::AcquireNextFrame is always in the un-rotated orientation, and the desktop image is rotated within the surface. For example, if the desktop is set to 768x1024 at 90 degrees rotation, AcquireNextFrame returns a 1024x768 surface with the desktop image rotated within it. Here are some rotation examples.
On a Win10 machine a 1920x1080 monitor in portrait mode will return an un-rotated image in 1920x1080. On Win8.1 the image I get matches the orientation of the monitor and is 1080x1920. This makes it really hard to try and handle both cases. My concern is that it is the video driver that is returning the image in 1080x1920 and that on Win10 I'll still have a problem. I'm trying to find an api that will tell me if the captured frame is rotated or un-rotated other than the width and height values. Because if the monitor is in landscaped (flipped) there is no way to determine what the orientation is.