PlanetSquires Forums

Support Forums => Other Software and Code => Topic started by: Wilko Verweij on October 26, 2016, 09:28:31 AM

Title: CreateTimerQueueTimer
Post by: Wilko Verweij on October 26, 2016, 09:28:31 AM
Hi,
I also asked this question at the Freebasic forum but it is waiting for approval there. I have a FireFly/Powerbasic program where I use the CreateTimerQueueTimer function as follows:
CreateTimerQueueTimer(hTimer, 0&, CodePtr(MyFunction),0&,1000,200,%WT_EXECUTEDEFAULT)
Works fine. I now try to convert this to Freebasic but have problems in understanding the third parameter. I thought it had to be:
CreateTimerQueueTimer(hTimer, 0&, ProcPtr(MyFunction), 0&, 2000, 1000, WT_EXECUTEDEFAULT)
but this compiles with an error: ''Passing different pointer types at parameter 3'. Even worse: the program crashes as this statement.
I noticed a difference in the include files: in Powerbasic it is
BYVAL Callback AS DWORD
in FreeBasic it is
byval Callback as WAITORTIMERCALLBACK
but I do not understand how to set the pointer to the callback function correctly. Any help is appreciated,
Wilko
Title: Re: CreateTimerQueueTimer
Post by: José Roca on October 26, 2016, 09:56:46 AM
I don't get an error. However, you can try:


SUB MyWaitOrTimerCallback (BYVAL lpParameter as PVOID, BYVAL TimerOrWaitFired as WINBOOLEAN)
   ' ...
   ' ...
   ' ...
END SUB

CreateTimerQueueTimer(hTimer, 0, cast(WAITORTIMERCALLBACK, ProcPtr(MyWaitOrTimerCallback)), 0, 2000, 1000, WT_EXECUTEDEFAULT)

Title: Re: CreateTimerQueueTimer
Post by: Wilko Verweij on October 26, 2016, 10:04:07 AM
Thanks for you fast answer. The program still crashes. I still use the original includes that come with FreeBasic. I assume you use your own. Is there a difference in includes for the CreateTimerQueueTimer function?
Regards, Wilko
Title: Re: CreateTimerQueueTimer
Post by: José Roca on October 26, 2016, 10:53:26 AM
No, I use the FB ones. I only have checked if it compiles, not if it does work.
Title: Re: CreateTimerQueueTimer
Post by: Wilko Verweij on October 26, 2016, 11:55:03 AM
OK, clear. I now tested the timeSetEvent and timeKillEvent function and that worked, when I changed the declare in the mmsystem.bi file to
declare function timeSetEvent(byval uDelay as UINT, byval uResolution as UINT, byval fptc as WNDPROC, byval dwUser as DWORD, byval fuEvent as UINT) as MMRESULT
(note the third parameter) in combination with the following code:
IDTimer = TimeSetEvent(250, 250,  CAST(WNDPROC, @MyFunction),0, TIME_PERIODIC)

I had seen these functions before but they are called 'obsolete' at msdn. But they still work...

Wilko