473,399 Members | 4,254 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,399 software developers and data experts.

problem with MMTimer [maybe OT]

Hi,

maybe OT...
I'm writing a windowless sw, I need a timer for each object that call a
non-static function ( myFunc() ) and refresh a value ( myValue ).

I've wrote this code:
class myClass {

public:

int myValue;

static void CALLBACK myClass::TimeProc(UINT uID,UINT uMsg,DWORD
dwUser,DWORD dw1,DWORD dw2) {
reinterpret_cast<myClass*>(dw1)->myFunc();

}

void myClass::myFunc () {
printf ("!! myFunc() !!");
myValue = 100;
}

void myClass::startTimer() {
MMRESULT myTimer =
timeSetEvent(1000,0,TimeProc,reinterpret_cast<DWOR D_PTR>(this),TIME_PERIODIC|TIME_CALLBACK_FUNCTION) ;
}

};

I've tryed to pass a class pointer to the static callback function.
myFunc () is called, but when I try to change myValue it returns
NullPointerException error

any ideas ???
ps: sorry for my horrible english :)
May 30 '06 #1
1 2317
Wasabi wrote:
I'm writing a windowless sw, I need a timer for each object that call
a non-static function ( myFunc() ) and refresh a value ( myValue ).

I've wrote this code:
class myClass {

public:

int myValue;

static void CALLBACK myClass::TimeProc(UINT uID,UINT uMsg,DWORD
Please do not use qualified names when declaring members inside the class
definition (just drop the "myClass::" here). Reduce the clutter!
dwUser,DWORD dw1,DWORD dw2) {
reinterpret_cast<myClass*>(dw1)->myFunc();
You cast your 'dw1' to be the object, but never check that what you got is
actually a non-null pointer before using it. Do check. Or assert.

}

void myClass::myFunc () {
printf ("!! myFunc() !!");
myValue = 100;
}

void myClass::startTimer() {
MMRESULT myTimer =
timeSetEvent(1000,0,TimeProc,reinterpret_cast<DWOR D_PTR>(this),TIME_PERIODIC|TIME_CALLBACK_FUNCTION) ;
}

};

I've tryed to pass a class pointer to the static callback function.
myFunc () is called, but when I try to change myValue it returns
NullPointerException error

any ideas ???


You don't show us how 'startTimer' is called, and for what object. It
can very well be that the object for which you call 'startTimer' is dead
by the time the timer starts ticking (and calling the function).

When the timer ticks, is it the same thread or different? If it's anoter
thread, you cannot allow it to use automatic objects, different threads
use different automatic object storage areas (stacks), most likely. You
need to call 'startTimer' for an object created dynamically (via 'new').

Of course, neither timers, nor threads, are topical here. You would be
much better off in the newsgroup that deals with your OS.

V
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask
May 30 '06 #2

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

Similar topics

2
by: Jeffrey Silverman | last post by:
First of all, I apologize for multiposting. I am now reposting and crossposting in an attempt to reach a broader audience. Here is the original posting... (with some small changes) I am tearing...
4
by: Madhu Gopinathan | last post by:
Hi All, I am faced with a horrible hang problem. I have a COM exe server that executes some tasks. The task execution manager is a thread that manages the pool of threads, which is 4 per processor....
1
by: Mauro | last post by:
Hi, I've a communication problem with my .NET web application and I need some suggestions. My application is composed of few ASP.NET pages running on a Windows 2003 Enterprise Server (.NET 1.1)....
11
by: ASP newbie | last post by:
I cannot run my asp.net application in w2k server. But the program works fine under w2k professional. Can anyone tell me is there any difference in the settings? Many thanks.
5
by: Mark | last post by:
I am struggling with a CSS2 layout problem, I am using Visual Web Developer 2005 Express. My website needs to be constrained within the visible viewport. This means that scrollable content will...
6
by: Tom | last post by:
I have a problem, to which I have been unable to find a solution for days now, after checking numerous references (both in books and online). Perhaps someone here can help. Here's my problem: ...
14
by: rurpy | last post by:
Another Python docs problem... I was trying to use imp.find_module(). >>> imp.find_module("mymod", "./subdir") ImportError: No frozen submodule named ./subdir.mymod subdir/mymod.py...
1
by: tom.eeraerts | last post by:
Hello, I have a problem migrating an application from v5r2 to v5r3. The problem is with the prepared statements. To see what the problem is, i extracted a small piece of code and debugged the...
4
by: Dan | last post by:
I'm using asp.net c# in my code behind I coded the following: ButtonAsynchronous.Attributes.Add("onclick", @" setTimeout( ""UpdateImg('AnimatedProgress','images/running.gif');"" , 50); "); ...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.