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 9151909
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T11:54:58+00:00 2026-06-17T11:54:58+00:00

Possible Duplicate: To pass a pointer to a member function When I move out

  • 0

Possible Duplicate:
To pass a pointer to a member function

When I move out of the class the WNDPROC DefEditProc; and EditKeyProc all works ok. But now as I pasted the code it fails compilation with error error: invalid use of member function (did you forget the '()' ?). So my question is how to squeeze this code into class so I do not pollute global namespace ?

#include <windows.h>
#include <richedit.h>

class richEdit {
  HWND richeditWindow;
  WNDPROC DefEditProc;
  public:

  LRESULT EditKeyProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam) {
    return CallWindowProc(DefEditProc, hwnd, uMsg, wParam, lParam);
  }
  richEdit() {
    HMODULE richedit_library = LoadLibrary("Msftedit.dll");
    if (NULL == richedit_library) abort();

    HINSTANCE hInstance = (HINSTANCE)GetModuleHandle(0);
    richeditWindow = CreateWindowExW (
      WS_EX_TOPMOST,
      MSFTEDIT_CLASS,
      L"window text",
      WS_OVERLAPPED | WS_SYSMENU | ES_MULTILINE | WS_VISIBLE,
      0, 0, 500, 500,
      NULL, NULL, hInstance, NULL
    );
    DefEditProc = (WNDPROC)SetWindowLong(richeditWindow, GWL_WNDPROC, (long)EditKeyProc);
  }
  ~richEdit() {
    MSG msg;
    while( GetMessageW( &msg, richeditWindow, 0, 0 ) ) {
      TranslateMessage( &msg );
      DispatchMessageW( &msg );
    }
  }
};

int main() {
  richEdit re;
}
  • 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-17T11:54:59+00:00Added an answer on June 17, 2026 at 11:54 am

    Try this:

    #include <windows.h>
    #include <richedit.h>
    
    class richEdit
    {
    private:
        HWND richeditWindow;
        WNDPROC DefEditProc;
    
        static LRESULT CALLBACK EditKeyProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
        {
            richEdit *pThis = (richEdit*) GetWindowLongPtr(hwnd, GWL_USERDATA);
            return CallWindowProc(pThis->DefEditProc, hwnd, uMsg, wParam, lParam);
        }
    
    public:
        richEdit()
            : richeditWindow(NULL), DefEditProc(NULL)
        {
            HMODULE richedit_library = LoadLibrary("Msftedit.dll");
            if (NULL == richedit_library) abort();
    
            HINSTANCE hInstance = (HINSTANCE)GetModuleHandle(0);
            richeditWindow = CreateWindowExW (
              WS_EX_TOPMOST,
              MSFTEDIT_CLASS,
              L"window text",
              WS_OVERLAPPED | WS_SYSMENU | ES_MULTILINE | WS_VISIBLE,
              0, 0, 500, 500,
              NULL, NULL, hInstance, NULL
            );
            if (NULL == richeditWindow) abort();
    
            SetWindowLongPtr(richeditWindow, GWL_USERDATA, (LONG_PTR)this);
            DefEditProc = (WNDPROC) SetWindowLongPtr(richeditWindow, GWL_WNDPROC, (LONG_PTR)&EditKeyProc);
        }
    
        ~richEdit()
        {
            if (richeditWindow != NULL)
            {
                SetWindowLongPtr(richeditWindow, GWL_WNDPROC, (LONG_PTR)DefEditProc);
                DestroyWindow(richeditWindow);
            }
        }
    };
    

    Or:

    #include <windows.h>
    #include <richedit.h>
    
    namespace myNS
    {
        LRESULT CALLBACK richEditKeyProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam);
    
        class richEdit
        {
        private:
            HWND richeditWindow;
            WNDPROC DefEditProc;
    
        public:
            richEdit()
                : richeditWindow(NULL), DefEditProc(NULL)
            {
                HMODULE richedit_library = LoadLibrary("Msftedit.dll");
                if (NULL == richedit_library) abort();
    
                HINSTANCE hInstance = (HINSTANCE)GetModuleHandle(0);
                richeditWindow = CreateWindowExW (
                  WS_EX_TOPMOST,
                  MSFTEDIT_CLASS,
                  L"window text",
                  WS_OVERLAPPED | WS_SYSMENU | ES_MULTILINE | WS_VISIBLE,
                  0, 0, 500, 500,
                  NULL, NULL, hInstance, NULL
                );
                if (NULL == richeditWindow) abort();
    
                SetWindowLongPtr(richeditWindow, GWL_USERDATA, (LONG_PTR)this);
                DefEditProc = (WNDPROC) SetWindowLongPtr(richeditWindow, GWL_WNDPROC, (LONG_PTR)&richEditKeyProc);
            }
    
            ~richEdit()
            {
                if (richeditWindow != NULL)
                {
                    SetWindowLongPtr(richeditWindow, GWL_WNDPROC, (LONG_PTR)DefEditProc);
                    DestroyWindow(richeditWindow);
                }
            }
        };
    
        LRESULT CALLBACK richEditKeyProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
        {
            richEdit *pThis = (richEdit*) GetWindowLongPtr(hwnd, GWL_USERDATA);
            return CallWindowProc(pThis->DefEditProc, hwnd, uMsg, wParam, lParam);
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Possible Duplicate: pass parameter in g:remoteLink as result of javascript function I am trying
Possible Duplicate: How do you pass a function as a parameter in C? Is
Possible Duplicate: How to pass text in a textbox to javascript function? I need
Possible Duplicate: Pass arbitrary number of parameters into Javascript function How can the following
Possible Duplicate: How to best pass methods into methods of the same class I've
Possible Duplicate: FAQ : How to pass objects to functions in C++? Pointer vs.
Possible Duplicate: Is Java pass by reference? when I used some java class like
Possible Duplicate: jquery .click pass parameters to user function $('#topleft').click(function (x) { loadPopupBox(); $(#popupinner).load('getdetail.php?id='
Possible Duplicate: Pass a buffer by reference to other function When I call the
Possible Duplicate: How to pass and call a function as an argument in Javascript?

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.