2
votes

I'm adding a call to the SetProcessDpiAwareness windows function as the first thing in my Delphi XE7 application (after dynamically loading the shcore DLL). I know it is preferable to use a manifest to set the DPIAware value and I've got that working separately and will use it eventually. However during development I want to use a command line parameter to set DPIAwareness value, otherwise I have to rebuild the app to change this status.

The problem is that SetProcessDpiAwareness returns the error code $800700A0. That is not documented in the function description, what does the code mean?

Ah I've found it, thanks to the answer to look at the parameter, I had declared the function type wrong, I had:

TSetDPIFunc = function (const PROCESS_DPI_AWARENESS) : HRESULT; stdcall;

but PROCESS_DPI_AWARENESS was not defined as an enum. Changed to the following and it now works fine:

TSetDPIFunc = function (const x: Integer) : HRESULT; stdcall;

1
Are you calling SetProcessDPIAwareness or SetProcessDPIAware? The title suggests the former. The latter does not return any error code, a nonzero return means the function have succeeded. Please edit the question to clear.Sertac Akyuz
In case you are indeed calling SetProcessDPIAwareNESS, please show us with which argument you call it!CherryDT
The function is SetProcessDpiAwareness, sorry typo in original post.kaj66

1 Answers

1
votes

0x8007XXXX is a Win32 error code encapsulated in a COM HRESULT using HRESULT_FROM_WIN32(). WIN32_FROM_HRESULT(0x800700A0) gives 0xA0, i.e. error code 160, which is ERROR_BAD_ARGUMENTS ("One or more of the input parameters are not correct").

It makes no sense for me though that you get this error, since this function doesn't even take any arguments!

So the only thing I can think of would be that it has something to with the issue described here, assuming you changed the DPI settings yourself for testing and it failed then:

So it seems that in order for SetProcessDPIAware (and the related approaches: SetProcessDpiAwareness() and manifest with true) to work correctly, one has to log out and login again after changing the DPI setting and before running the program.

By the way, in case this is helpful: For testing manifests without totally rebuilding, you could use mt.exe to attach a manifest to your application from the command line.