Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Timers don't work in DLLs
Message
 
To
06/09/2010 18:46:31
Joel Leach
Memorial Business Systems, Inc.
Tennessee, United States
General information
Forum:
Visual FoxPro
Category:
COM/DCOM and OLE Automation
Environment versions
Visual FoxPro:
VFP 9 SP2
OS:
Windows 7
Miscellaneous
Thread ID:
01480101
Message ID:
01480364
Views:
99
Why not just use MTmyVFP (http://mtmyvfp.codeplex.com/releases/view/50370) for your ParallelFox code threads? The basic stuff is written by Calvin Hsia of Microsoft so it's not going to get any better than that. (I must admit I don't understand the bias against Calvin - the guy's a genius!). No C++ code or C++ dll required - just pure foxpro code.

Here's the code that's proven to work in a VFP mtdll using a C++ timer:

1) go get this .ZIP file from here:
http://download.com.com/3000-2401-889219.html?tag=lst-0-1
2) unzip the .EXE and regsvr32 the associated .DLL
regsvr32.exe ccrpTmr.dll
3) Build the following code as a MTDLL:
DEFINE CLASS TimerTest AS CUSTOM OLEPUBLIC
     oTimerControl = .NULL.
     oTimerEventHandler = .NULL.
     PROCEDURE INIT
          ** Create the timer object
          THIS.oTimerControl = CREATEOBJECT( "ccrpTimers.ccrpTimer" )
          ** Create the event handler
          THIS.oTimerEventHandler = CREATEOBJECT( "TimerEventHandler" )
          ** Attach the eventhandler to the timer control
          EVENTHANDLER( THIS.oTimerControl, THIS.oTimerEventHandler )
          ** Set the timer properties
          ** As soon as your set enabled to .T., the timer will begin functioning
          ** Event type, 0 - one shot timer event, 1 - Periodic timer events
          THIS.oTimerControl.EventType = 1
          THIS.oTimerControl.INTERVAL = 1000
          THIS.oTimerControl.ENABLED = .T.
     ENDPROC
ENDDEFINE
** Replace the path in the IMPLEMENTS line with the path where you  installed ccrptmr.dll
DEFINE CLASS TimerEventHandler AS SESSION
     IMPLEMENTS __ccrpTimer IN "c:\ccrp\ccrptmr.dll"
     PROCEDURE __ccrpTimer_Timer( Milliseconds AS NUMBER ) AS VOID ;
               HELPSTRING "Event that fires whenever [Interval] milliseconds elapses."
          ** Your timer event code goes here
          IF !DIRECTORY( "c:\temp\" )
               MD c:\temp          ENDIF
          =STRTOFILE( "", "c:\temp\" + ALLTRIM( STR( SECONDS(), 12, 2 )) + ".txt" )
     ENDPROC
ENDDEFINE
4) Instantiate the class:
oCom = CREATEOBJECT( "TimerTest.TimerTest" )
That's it! Your timer events will now function correctly in a VFP MTDLL.
One final thing to remember. Before you release the object (in the case of above, oCom) you must set the enabled property of the timer control to .F. like this:
oCom.oTimerControl.Enabled = .F.
Otherwise VFP will crash with a C00005 error.
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform