vb.netwinapihdpi

Unknown SetProcessDpiAwareness Error Result


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.


Solution

  • 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.