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

  • Home
  • SEARCH
  • 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 8635415
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T09:58:09+00:00 2026-06-12T09:58:09+00:00

I’m thinking of creating a Window class library that uses Win32 API and C++

  • 0

I’m thinking of creating a Window class library that uses Win32 API and C++ standard libraries
And I’d like to add signal/slot functionality that handles window messages.

using namespace std;
using namespace boost::signals2;
typedef signal<void (Window*, EventArgs*)> WndEvent; 

class EventArgs { public: HWND hWnd; WPARAM wParam; LPARAM lParam; };

class Window {
    protected: unordered_map<UINT, WndMsg*> msgMap;
    public: void addMsgHandler(UINT msg, void (*handler)(Window*, EventArgs*)) {
        auto iter=msgMap.find(msg);
        if(iter==msgMap.end()) {
            WndEvent* newEvent = new WndEvent();
            newEvent->connect(handler);
            msgMap.insert(make_pair(msg, newEvent));
        }
        else iter->second->connect(handler);
    }

    private: LRESULT wndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lparam) {
        for(auto iter=msgMap.begin(); iter!=msgMap.end(); iter++)
            iter->second->();
    }
};

In using that library:

class Form : public Window {
    void initialize() {// add here pair of 'message' and 'corresponding handler'
        addMsgHandler(WM_LBUTTONUP, boost::bind(&Form::onLButtonUp, this, _1, _2));
        ...
    }
    void onLButtonUp(Window* sender, EventArgs* e) { // event handler
        wchar_t buf[1000]; 
        wsprintf(buf, L"(%d, %d) clicked", GET_X_LPARAM(e->lParam), GET_Y_LPARAM(e->lParam));
        MessageBox(0, buf, L"", MB_OK);
    }
}

Here the problem is onLButtonUp’s signature doesn’t match since it’s a class member function.
So I tried to use boost::bind and I got compile error like this:

 Window::addMsgHandler': cannot convert parameter 2 'boost::_bi::bind_t<R,F,L>' to 'void (__cdecl *)(Window *,EventArgs *)'

which means I have to change (from simple function pointer to boost function object?) the signature of addMsgHandler() but

I cannot determine the data type (with very long template parameters) to be passed.

The compile error message says

R=void,            
F=boost::_mfi::mf2<void,Form,Window *,EventArgs *>,1>                           
L=boost::_bi::list3<boost::_bi::value<Form*>,boost::arg<1>,boost::arg<2>>                

Furthermore, since many other classes will be derived from class Window, I cannot know the template type when I define class Window.

Is there a proper way to pass boost.bind object as function parameter?

  • 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-12T09:58:11+00:00Added an answer on June 12, 2026 at 9:58 am

    Define it like this:

    void addMsgHandler(UINT msg, const function<void(Window* , EventArgs*)>& slot);
    

    Or even like this:

    void addMsgHandler(UINT msg, const WndEvent::slot_type &slot);
    

    Now, when calling this function, slot parameter should be a “callable” accepting 2 arguments of types Window * and EventArgs *, and you can create such a slot using mem_fn, boost::bind, std::bind, or just passing an appropriate raw function ptr.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I've got a string that has curly quotes in it. I'd like to replace
I am doing a simple coin flipping experiment for class that involves flipping a
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I would like to count the length of a string with PHP. The string
For some reason, after submitting a string like this Jack’s Spindle from a text
I have a French site that I want to parse, but am running into
I am trying to render a haml file in a javascript response like so:

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.