Issues obtaining info from SystemParametersInfo

Hello everyone,

Version: 25.2.5.2 (X86_64) / LibreOffice Community
Build ID: 03d19516eb2e1dd5d4ccd751a0d6f35f35e08022
CPU threads: 16; OS: Windows 11 X86_64 (10.0 build 26100); UI render: Skia/Raster; VCL: win
Locale: en-CA (en_CA); UI: en-US
Calc: threaded

I’m trying to determine size of screen without the task bar. For some reason the API call is not returning any information back. Although, I’m not getting any error message, could there be anything wrong with the values I’m passing?

Option Explicit

Declare Function SystemParametersInfo Lib “user32” Alias “SystemParametersInfoA” _
(ByVal uAction As Long, ByVal uParam As Long, ByVal lpvParam As Any, ByVal fuWinIni As long) As Long

Type screenRect
x1 As Long
x2 As Long
x3 As Long
x4 As Long
End type

Sub testSPI()
Dim rect As screenRect
Dim result

result = SystemParametersInfo(48, 0, rect, 0)
freelibrary(“user32.dll”)
End Sub

Any help would be very appreciated.

Thank you for this. However, any idea why wouldn’t the call to DLL work?

nope. maybe because SystemParametersInfoA returns a Boolean, not a Long ?
SystemParametersInfoA function (winuser.h) - Win32 apps | Microsoft Learn

just checkin, does it work for the documented example : Declare Statement ?

Indeed I did make a mistake there, but I just tried with a proper definition and no luck. Nonetheless, thank you for the suggestion.

change to

ByRef lpvParam As Any

then the declare works
Good luck,
ms777

2 Likes

This completely makes sense as the third variable is in/out. Thank you so much!!