I want to retrieve the effective DPI awareness value for a specified process ID in Windows 10 Pro 64-bit. The value I need is one of the PROCESS_DPI_AWARENESS I can get with the WinAPI GetProcessDpiAwareness function.
To implement what I need, I wrote a simple one-window C# WPF app in VS 2015. I enter the process ID I'm interested in into the TextBox txtProcessID and the result is displayed in the TextBlock txtResult when I press the txtProcessID button:
private const int S_OK = 0;
private enum PROCESS_DPI_AWARENESS
{
PROCESS_DPI_UNAWARE = 0,
PROCESS_SYSTEM_DPI_AWARE = 1,
PROCESS_PER_MONITOR_DPI_AWARE = 2
}
[DllImport("Shcore.dll")]
private static extern int GetProcessDpiAwareness(IntPtr hprocess, out PROCESS_DPI_AWARENESS value);
private void btnGetDPIAwareness_Click(object sender, RoutedEventArgs e)
{
int procIDint = int.Parse(txtProcessID.Text);
IntPtr procID = new IntPtr(procIDint);
PROCESS_DPI_AWARENESS value;
int res = GetProcessDpiAwareness(procID, out value);
if (res == S_OK)
txtResult.Text = value.ToString();
else
txtResult.Text = "Error: " + res.ToString("X");
}
But calling GetProcessDpiAwareness for any process always give me an error E_INVALIDARG. What am I doing wrong?