Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7743265
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T09:29:20+00:00 2026-06-01T09:29:20+00:00

I have this static callback function in MyClass, and I try to call another

  • 0

I have this static callback function in MyClass, and I try to call another static function from it. There is a problem however, one of the arguments that Register() takes is a non-static class variable.

I thought of using the “this” keyword to overcome this problem but it seems I am unable to (‘this’ : can only be referenced inside non-static member functions). Here is my code:

class MyClass
{
...
    static LRESULT CALLBACK klHkProc(int nCode, WPARAM wParam, LPARAM lParam);
    static BOOL Register(DWORD vKey,KEYBLOCK* ptrKEYBLOCK);
    KEYBLOCK *kb;       
...

}
LRESULT CALLBACK MyClass::klHkProc(int nCode, WPARAM wParam, LPARAM lParam)
{
    PKBDLLHOOKSTRUCT p = (PKBDLLHOOKSTRUCT) (lParam);
    if (wParam == WM_KEYDOWN) 
    {
        MyClass::Register(p->vkCode,this->kb);
    }
    return CallNextHookEx(NULL, nCode, wParam, lParam);
}

Any suggestions?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-01T09:29:22+00:00Added an answer on June 1, 2026 at 9:29 am

    Given what you wrote it is hard to answer this without more information.

    However, assuming that all instances of MyClass should be processed, I suggest adding a static std::list<MyClass *> into which you place each instance’s this pointer in the constructor for MyClass and then in the destructor of MyClass to remove the this from this list.

    Then in your static klHkProc() you would iterate over the static list of all instances of MyClass and for each one call MyClass::Register() with the kb of each such registered instance of MyClass.

    Here is a rough outline of the code to do this:

    class MyClass
    {
    ...
    public:
        static LRESULT CALLBACK klHkProc(int nCode, WPARAM wParam, LPARAM lParam);
        static BOOL Register(DWORD vKey,KEYBLOCK* ptrKEYBLOCK);
        static std::list<MyClass *> allInstances;
        KEYBLOCK *kb;
    
        MyClass() {
          ...
          allInstances.push_back(this);
          ...
        }
        ~MyClass() {
          ...
          // Assumes not a huge list of instances as this is O(n) and thus destruction
          // of all instances of MyClass in O(n^2) on the number of instances.
          allInstances.remove(this);
          ...
        }
    
    ...
    };
    
    LRESULT CALLBACK MyClass::klHkProc(int nCode, WPARAM wParam, LPARAM lParam)
    {
        PKBDLLHOOKSTRUCT p = (PKBDLLHOOKSTRUCT) (lParam);
        if (wParam == WM_KEYDOWN)
        {
            std::list<MyClass *> itr = allInstances.begin();
            std::list<MyClass *> end = allInstances.end();
            for (; itr != end; ++itr) {
              MyClass *current = *itr;
              MyClass::Register(p->vkCode, current->kb);
            }
        }
        return CallNextHookEx(NULL, nCode, wParam, lParam);
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a class, in which i declare a static function. I register this
I am trying to code a static callback function that is called frequently from
I have a callback function for another function that loops through the comments of
I have a static function callback : static SCDynamicStoreCallBack callback( [params] ){ ... }
I have a static C library where I have non static call back function.
I have this code: protected static string MakeGetRequest(string url, Action<IAsyncResult> callback) { var request
Currently i have this method: static boolean checkDecimalPlaces(double d, int decimalPlaces){ if (d==0) return
I have this class: public static class CsvWriter { private static StreamWriter _writer =
I have this code public static Boolean freq[] = new Boolean[Global.iParameter[2]]; freq[Global.iParameter[2]] = false;
I have this regex: private static final String SPACE_PATH_REGEX =[a-z|A-Z|0-9|\\/|\\-|\\_|\\+]+; I check if my

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.