CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 8 of 8
  1. #1
    Join Date
    Jan 2006
    Posts
    35

    timeSetTimer Callback Issues

    I have a compilation error I can't figure out. I am calling timeSetTimer from a member function within a class. The callback function is also a member of the class.

    When I compile this statement:

    timeSetEvent(iDelay, 0, &wait, NULL, TIME_ONESHOT);

    I get:

    error C2276: '&' : illegal operation on bound member function expression

    When I compile this statement:

    timeSetEvent(iDelay, 0, &FOO::wait, NULL, TIME_ONESHOT);

    I get:

    error C2664: 'timeSetEvent' : cannot convert parameter 3 from 'void (__stdcall FOO::*)(unsigned int,unsigned int,unsigned long,unsigned long,unsigned long)' to 'void (__stdcall *)(unsigned

    Any ideas?

    Thanks!

  2. #2
    Join Date
    May 2000
    Location
    KY, USA
    Posts
    18,652

    Re: timeSetTimer Callback Issues


  3. #3
    Join Date
    Jan 2006
    Posts
    35

    Re: timeSetTimer Callback Issues

    Makes sense... Thanks!

  4. #4
    Join Date
    May 2000
    Location
    KY, USA
    Posts
    18,652

    Re: timeSetTimer Callback Issues

    You are welcome...

  5. #5
    Join Date
    Jan 2006
    Posts
    35

    Re: timeSetTimer Callback Issues

    Ok... I am back with a similar issue. I've decided to place a flag in the callback function that I will clear upon execution. I have the flag as a private member of the class. When I attempt to clear it inside the callback function with:

    pulsing=false;

    I get:

    illegal reference to data member 'FOO:ulsing' in a static member function

    The error makes sense because the this pointer is not passed along. I figured declaring the flag as

    static bool pulsing;

    would solve this issue... but that generates an unresolved external symbol.

    Any help?

  6. #6
    Join Date
    May 2000
    Location
    KY, USA
    Posts
    18,652

    Re: timeSetTimer Callback Issues

    You basically have two choices here...
    • Using a static member. They need to be defined however, thus...
      Code:
      // .hpp
      class foo
      {
        static bool pulsing;
      };
      
      // .cpp
      bool foo::pulsing = false;

    • 'timeSetEvent()' allows you to pass a user-defined value as a 'DWORD_PTR'. You can use this to pass the 'this' pointer of the class instance you want to access in your callback...

  7. #7
    Join Date
    Jan 2006
    Posts
    35

    Re: timeSetTimer Callback Issues

    I ended up using the DWORD dwUser parm to pass the pointer this to the function. I couldn't get your first example to work. I had actually tried that. It doesn't seem to like the static bool pulsing declaration. I still get the unresolved external symbol error.

    Even though I have it working I would still like to know why declaring the flag as static doesn't work for me.

    Thanks!

  8. #8
    Join Date
    May 2000
    Location
    KY, USA
    Posts
    18,652

    Re: timeSetTimer Callback Issues

    Quote Originally Posted by eeboy
    Even though I have it working I would still like to know why declaring the flag as static doesn't work for me.
    Well...without seeing the actual you tried it with, it is pretty hard to tell...nevertheless, it should have worked.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured