473,218 Members | 1,868 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,218 software developers and data experts.

timSetEvent in C# - Passing object to static function

Has anyone used the multimedia timere timeSetEvent in C#? I'm trying
to use it to get a 1ms accurate timer. All the other implementations
are far to inaccurate in their resolution. 1ms Timer = 0ms.....60ms.
I'm already timing the callbacks using the Win32API
QueryPerformanceCounter/Frequency. The code I have is actually
performing the callback and it looks like it is close to 1ms but I now
need to get my object passed to this static event so I can make some
instance calls. Can anyone help? I know that I could do this in
standard C or C++ by passing the class as a pointer when I register
the Timer Callback (the lUserData parameter to timeSetEvent):

public sealed class Win32TimingFunctions
public delegate void TIMECALLBACK(uint wTimerID, uint msg, uint
dwUser, uint dw1, uint dw2);
public struct TIMECAPS
public uint wPeriodMin; /* minimum period supported */
public uint wPeriodMax; /* maximum period supported */

public enum EVENT_TYPE : uint
TIME_ONESHOT = 0x0000, /* program timer for single event */
TIME_PERIODIC = 0x0001 /* program for continuous periodic event */
public enum CALLBACK_TYPE : uint
TIME_CALLBACK_FUNCTION = 0x0000, /* callback is function */
TIME_CALLBACK_EVENT_SET = 0x0010, /* callback is event - use
SetEvent */
TIME_CALLBACK_EVENT_PULSE = 0x0020 /* callback is event - use
PulseEvent */

[DllImport("winmm.dll", CallingConvention=CallingConvention.Winapi)]
public extern static uint timeSetEvent(uint uDelay, uint
uResolution, TIMECALLBACK lpFunction, IntPtr dwUser, EVENT_TYPE
[DllImport("winmm.dll", CallingConvention=CallingConvention.Winapi)]
public extern static uint timeKillEvent(uint uTimerID);

public class TimerClass
private int m_nInstanceNumber = 0;
private static uint m_snTimerID = uint.MaxValue;
public void StartTimer()
if (m_snTimerID == uint.MaxValue)
Win32TimingFunctions.EVENT_TYPE uTypeEvent;
uint uElapse = 1;
uint uResolution = 0;
IntPtr lUserData = IntPtr.Zero;
m_callback = new
Win32TimingFunctions.TIMECALLBACK(TIMECALLBACK_Sen dMessage);
m_snMsgsToSend = (uint)numUpDownNumMsgs.Value;
m_snMsgsSent = 0;

if (numUpDownNumMsgs.Value > 1)
uTypeEvent = Win32TimingFunctions.EVENT_TYPE.TIME_PERIODIC;
uTypeEvent = Win32TimingFunctions.EVENT_TYPE.TIME_ONESHOT;
// Set minimum System timing

// Setup Callback function
m_snTimerID = Win32TimingFunctions.timeSetEvent(
uElapse, //period (in milliseconds)
uResolution, //resolution (0=maximum)
m_callback, //callback function
lUserData, //no user data
uTypeEvent); //periodic timer
m_snTimerID = uint.MaxValue;
static void TIMECALLBACK_SendMessage(uint wTimerID, uint msg, uint
dwUser, uint dw1, uint dw2)
// What I'd like to do
TimerClass pInstance = dwUser as TimerClass;
public bool InstanceMethod()
Console.WriteLine("Member variable {0}",m_InstanceNumber);

Thanks for any help or direction.

Jeff Holtz
Nov 15 '05 #1
0 3271

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

by: Newsgroup - Ann | last post by:
Gurus, I have the following implementation of a member function: class A { // ... virtual double func(double v); void caller(int i, int j, double (* callee)(double)); void foo() {caller(1,...
by: James Vanns | last post by:
Sounds nasty doesn't it!! Well it's kinda what I need to do! I have an external C struct (external to the C++ project/classes etc.) which is wants a function ptr assigned to one of it's members: ...
by: Steven T. Hatton | last post by:
I am trying to convert some basic OpenGL code to an OO form. This is the C version of the program: http://www.opengl.org/resources/code/basics/redbook/double.c You can see what my current...
by: Ryan | last post by:
Hi All, I quite new to c# development but I'm getting to grips with it quite well comming from a mainly C++ / Delphi background. I've been following the msdn artical entitled "An Introduction to...
by: dice | last post by:
Hi, In order to use an external api call that requires a function pointer I am currently creating static wrappers to call my objects functions. I want to re-jig this so I only need 1 static...
by: StephQ | last post by:
This is from a thread that I posted on another forum some days ago. I didn't get any response, so I'm proposing it in this ng in hope of better luck :) The standard explanation is that pointer...
by: =?Utf-8?B?VmljdG9yIExhaQ==?= | last post by:
Hi, I wrote an simple application using VS2005 C#. I am trying to call some functions in my other dll file. This dll is written in EVC for running on Windows CE 5.0. This dll file has the...
by: grbgooglefan | last post by:
I am trying to pass a C++ object to Python function. This Python function then calls another C++ function which then uses this C++ object to call methods of that object's class. I tried...
by: Bryan Parkoff | last post by:
I write my large project in C++ source code. My C++ source code contains approximate four thousand small functions. Most of them are inline. I define variables and functions in the global scope....
by: veera ravala | last post by:
ServiceNow is a powerful cloud-based platform that offers a wide range of services to help organizations manage their workflows, operations, and IT services more efficiently. At its core, ServiceNow...
by: VivesProcSPL | last post by:
Obviously, one of the original purposes of SQL is to make data query processing easy. The language uses many English-like terms and syntax in an effort to make it easy to learn, particularly for...
by: mar23 | last post by:
Here's the situation. I have a form called frmDiceInventory with subform called subfrmDice. The subform's control source is linked to a query called qryDiceInventory. I've been trying to pick up the...
by: abbasky | last post by:
### Vandf component communication method one: data sharing ​ Vandf components can achieve data exchange through data sharing, state sharing, events, and other methods. Vandf's data exchange method...
by: jimatqsi | last post by:
The boss wants the word "CONFIDENTIAL" overlaying certain reports. He wants it large, slanted across the page, on every page, very light gray, outlined letters, not block letters. I thought Word Art...
by: fareedcanada | last post by:
Hello I am trying to split number on their count. suppose i have 121314151617 (12cnt) then number should be split like 12,13,14,15,16,17 and if 11314151617 (11cnt) then should be split like...
by: stefan129 | last post by:
Hey forum members, I'm exploring options for SSL certificates for multiple domains. Has anyone had experience with multi-domain SSL certificates? Any recommendations on reliable providers or specific...
by: egorbl4 | last post by:
Скачал я git, хотел начать настройку, а там вылезло вот это Что это? Что мне с этим делать? ...
by: MeoLessi9 | last post by:
I have VirtualBox installed on Windows 11 and now I would like to install Kali on a virtual machine. However, on the official website, I see two options: "Installer images" and "Virtual machines"....

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.