Magnifier API Issues Resolution

Job ID: 40271800

Budget: $50 – $150 USD

Hello,

I am developing a screen capture tool for a multi-monitor environment using the Windows Magnification API.

While the capture works perfectly when all monitors have the same resolution and the primary monitor starts at (0, 0), I am encountering crashes (Access Violation) or capture failures in the following specific scenarios:

Resolution Mismatch: When the primary monitor's resolution is smaller than the secondary monitor's (e.g., Primary: 1680x1050, Secondary: 1920x1080 or 4K).

Negative Coordinates: When the virtual screen's origin starts at a negative value (e.g., x=0, y=-20), which often happens due to monitor alignment in Windows settings.

Current Setup:
* OS: Windows 10 / 11
* Development Environment: Visual Studio 2017 (C++, Win32 API)
* Approach: I created a WS_POPUP Host window and a Magnifier control as its child.

The Issue:
Whenever I call MagSetWindowSource or SetWindowPos for the magnifier control on the higher-resolution or negatively-positioned monitor, the application either crashes or fails to trigger the MagImageScalingCallback. It seems like the API has trouble calculating internal buffer offsets when the target area exceeds the primary monitor's bounds or involves negative coordinates.

What I've tried:

* Called SetProcessDpiAwarenessContext(DPI_AWARENESS_CONTEXT_PER_MONITOR_AWARE_V2).
* Clamped the source RECT to the virtual screen bounds using GetSystemMetrics(SM_XVIRTUALSCREEN).
* Re-positioned the Host window to the target monitor's origin before capturing.

Could you please provide guidance or a robust code snippet to handle these mixed-resolution and negative coordinate issues?

Any help would be greatly appreciated. Thank you!