0

I have 1 computer out of 50 that is returning a non zero result from SetProcessDpiAwareness and I can't find any information on it. I am setting the DPI Awareness to Unaware. I have one computer that is returning a value of 105621835743232(Decimal). It seems to still be setting the DPI Awareness to unaware like it should but gives a return value that is not expected.

Private Declare Function SetProcessDpiAwareness Lib "shcore.dll" (ByVal Value As PROCESS_DPI_AWARENESS) As Long

Private Function SetDPI() As Long
    'Results from SetProcessDPIAwareness
    'Const S_OK = &H0&
    'Const E_INVALIDARG = &H80070057
    'Const E_ACCESSDENIED = &H80070005
    Dim lngResult As Long
    lngResult = SetProcessDpiAwareness(PROCESS_DPI_AWARENESS.Process_DPI_Unaware)
    Return lngResult

End Function

This is a clickonce winforms application so I can't use the manifest to set DPI.

Any help with locating documentation would be greatly welcomed!

Thanks in advance.

Jonathan Potter
  • 36,172
  • 4
  • 64
  • 79
Nathan
  • 789
  • 11
  • 20

1 Answers1

5

This API function's return value is a 32 bit integer so you should use Integer rather than Long. Note that Long is a 64 bit type.

I also strongly recommend using p/invoke rather than Declare. The latter exists for compatibility reasons. P/invoke offers much greater control of the import process.

David Heffernan
  • 601,492
  • 42
  • 1,072
  • 1,490
  • 4
    Decimal 105621835743232 is hex 0x0000601000000000. The lower 32 bits are all 0s, which means the function is actually returning an HRESULT of 0x00000000, aka S_OK: "*The DPI awareness for the app was set successfully.*" – Remy Lebeau Jun 05 '18 at 05:28
  • Thanks for the catch David. I read the documentation for that call a bunch of time and missed the fact that the return was a 32 bit integer. That makes much more sense as to why it was still working even though it was return a non zero number. – Nathan Jun 05 '18 at 12:36