Using "SetTimer()" to Call a non-static Function

Discussion in 'C++' started by KevinSimonson, Nov 4, 2010.

  1. I'm in a situation where I need to call a non-static function every
    fifteen minutes. I read the article at "http://www.codeproject.com/KB/
    cpp/SetTimer__non-static.aspx?display=Print", that told me how to use
    "SetTimer()" with callback to a non-static member function, and used
    the author's basic idea, though I didn't write a callback wrapper
    function. His idea was basically to create a static variable of type
    "void *" in the class, and before my code calls "SetTimer()", it sets
    that "void *" object to "this". I've got the "void *" object declared
    as public in my header file. Then the author said to put a line that
    says "void* CHomeSearchCtrl::chsObject;" in my implementation to match
    the header file, which I did. Then in my callback function I cast
    "chsObject" back to type "CHomeSearchCtrl" and store it in variable
    "hsc", and then I call "hsc->Search( true, true);" ("Search()" is the
    non-static function that needs to be called every fifteen minutes.

    Then I try to compile this code, and I get the message,
    "1>c:\program files\microsoft visual studio 10.0\vc\include
    \fstream(890): error
    C2248:'std::basic_ios<_Elem,_Traits> ::basic_ios' : cannot access
    private member declared in class 'std::basic_ios<_Elem,_Traits>'".

    Isn't this kind of bizarre? I mean, it's not complaining about my
    code, is it? Instead it's complaining about
    "vc\include\fstream"! How can changes I make to my local code be
    causing compilation errors in "vc\include\fstream", that I have
    absolutely no control over?

    Anyhow, I'm kind of lost. Is someone could point out to me how I can
    get my project compiled I'd really appreciate it. My operating system
    is Windows XP and I'm compiling on Visual Studio (version
    10.0.30319.1).

    Kevin S
    KevinSimonson, Nov 4, 2010
    #1
    1. Advertising

  2. KevinSimonson

    Ian Collins Guest

    On 11/ 5/10 08:21 AM, KevinSimonson wrote:
    > I'm in a situation where I need to call a non-static function every
    > fifteen minutes. I read the article at "http://www.codeproject.com/KB/
    > cpp/SetTimer__non-static.aspx?display=Print", that told me how to use
    > "SetTimer()" with callback to a non-static member function,


    Your really should ask this on a windows programming group.

    --
    Ian Collins
    Ian Collins, Nov 4, 2010
    #2
    1. Advertising

  3. KevinSimonson

    Geoff Guest

    On Thu, 4 Nov 2010 12:21:35 -0700 (PDT), KevinSimonson
    <> wrote:

    http://www.codeproject.com/KB/cpp/SetTimer__non-static.aspx?display=Print

    [snip]

    >though I didn't write a callback wrapper
    >function.


    [snip]

    Did you wonder why the original author had to write a wrapper
    function? Perhaps it was related to a class object that had to be
    passed to a non-C++ Windows API?

    Why do you think you don't need it?

    Win32 API is not C++. Windows MFC is a very thin C++ wrapper to the
    Win32 API. Do not confuse Windows programming with standard C++.

    You might find more activity and more people who can respond directly
    to your Windows programming questions here:

    http://www.microsoft.com/communities/forums/default.mspx

    Microsoft is in the process of abandoning Usenet as a support channel
    and regards their web forums as a better medium.
    Geoff, Nov 5, 2010
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Victor Bazarov
    Replies:
    0
    Views:
    1,349
    Victor Bazarov
    Jun 23, 2003
  2. Replies:
    4
    Views:
    1,049
    Richard Tobin
    Dec 12, 2006
  3. Replies:
    2
    Views:
    503
    Jonathan Mcdougall
    Aug 6, 2007
  4. dolphin
    Replies:
    3
    Views:
    1,324
    Pete Becker
    Dec 5, 2007
  5. rickman
    Replies:
    5
    Views:
    413
    rickman
    Mar 30, 2013
Loading...

Share This Page