SetTimer declare for Windows?

Does someone have a Declare line for the SetTimer function on Windows?

It thought about making an example project for declares, but it doesn’t work.
I may have a little problem.

Declare Function SetTimer Lib "user32.dll" (hwnd As ptr, ID As Integer, delay As UInt32, callback As Ptr) As Integer
myTimerCallback = AddressOf Callback

Dim p As ptr = myTimerCallback
Log "Callback function: "+Str(p)

Dim n As Integer = SetTimer(Nil, &h87654321, 1000, p)
Log "Timer created: "+Str(n)

and the callback method:

Public Sub Callback(Arg1 as ptr, Arg2 as UInt32, Arg3 as ptr, Arg4 as UInt32)
  #Pragma X86CallingConvention StdCall
  #Pragma BackgroundTasks False
  #Pragma StackOverflowChecking False
  Dim d As New date
  Log CurrentMethodName+": "+d.SQLDateTime
End Sub

I got the timer ID returned, but the callback is never invoked.

1 Like

The callback method must be a shared method or module method.

1 Like

Thanks. Now it works with global method.
Although I think that’s more a limitation in how Xojo works…

1 Like

but with xojo you can also write hooks to handle low-level system events ?

You better specify which hooks.
Via plugin we can accept a few things and handle them thread safe.

like this

Check the WindowsKeyFilterMBS class in MBS Xojo Win Plugin.

Or see the following for some pointers Shortcut Key That Works Globally - General - Xojo Programming Forum (just remember to ask a mod for permission to speak there and open the thread if you want to carry on the conversation there :roll_eyes:)

or see arbp/WFS: Windows Functionality Suite (

and if you need hot keys, just check HotKeyMBS class, which works for macOS and Windows.