Option Explicit
Private Declare Function CloseHandle Lib "kernel32" (ByVal hObject As Long) As Long
Private Declare Function GetExitCodeProcess Lib "kernel32" (ByVal hProcess As Long, lpExitCode As Long) As Long
Function TimerCreate() As Boolean
If g_CTimer Is Nothing Then Exit Function
' Create the timer
g_CTimer.TimerID = SetTimer(0&, 0&, g_CTimer.Interval, AddressOf TimerProc)
If g_CTimer.TimerID Then
TimerCreate = True
Else
TimerCreate = False
g_CTimer.TimerID = 0
End If
End Function
Sub TimerProc(ByVal hwnd As Long, ByVal uMsg As Long, ByVal idEvent As Long, ByVal dwTime As Long)
On Error Resume Next
If g_CTimer Is Nothing Then Exit Sub
g_CTimer.ThatTime
End Sub
Asked
Active
Viewed 284 times
-4

Jim Mischel
- 131,090
- 20
- 188
- 351

apratik
- 141
- 2
- 11
-
1You really need to ask a question. Is there something in particular you're having trouble with? Seems like a few minutes' study would get you about 95% there with a conversion. Then you could ask a *specific* question about whatever you're having trouble with. – Jim Mischel Jul 25 '13 at 19:42
-
i am having trouble while writing below line in C# with correct parameters and data type: `g_CTimer.TimerID = SetTimer(0&, 0&, g_CTimer.Interval, AddressOf TimerProc)` – apratik Jul 25 '13 at 19:45
-
1You don't need any of that in C# because in .Net there are several `Timer` and the like classes that already do whatever you're doing here. What I mean is that a `VB6 -> C#` migration is not just translating the code. You need a full rewrite using .Net classes and OOP philosophy. – Federico Berasategui Jul 25 '13 at 19:46
1 Answers
1
For a timer, you probably want:
System.Threading.Timer myTimer =
new System.Threading.Timer(TimerProc, null, g_CTimer.Interval, g_CTimer.Interval);
If you really need to use the multimedia timers (I would not recommend it), I'd suggest you read up on Windows Timers and check pinvoke.net for managed prototypes. For example, SetTimer.

Jim Mischel
- 131,090
- 20
- 188
- 351