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
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)
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
No, I use the FB ones. I only have checked if it compiles, not if it does work.
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