On 21.07.2015 at 22:19 Eric Jensen wrote:
> Hello Andreas,
> Tuesday, July 21, 2015, 9:29:02 PM, you wrote:
AF>> macro magic doesn't make things easier for beginners. So this is what
AF>> I came up with:
AF>> class wxMyUserData: public wxObject
AF>> {
AF>> wxDECLARE_ABSTRACT_CLASS(wxMyUserData);
AF>> public: void *data;
AF>> };
AF>> wxIMPLEMENT_ABSTRACT_CLASS(wxMyUserData, wxObject);
AF>> And then to connect the event handler:
AF>> wxMyUserData *ud = new wxMyUserData;
AF>> ud->data = ...;
AF>> mybutton->Bind(wxEVT_COMMAND_BUTTON_CLICKED, mycallback, wxID_ANY, wxID_ANY, ud)
AF>> As I said, it's working fine but I'd be more relaxed if somebody could
AF>> confirm that the code is indeed alright.
> It would be interesting to hear about the "bigger picture" of what
> you're trying to implement.
As I said, I'm writing a wxWidgets backend for a cross-platform GUI API
which is completely in C. It's all rather abstract stuff and of course
not your typical wxWidgets application. My aim is not to write beautiful
wxWidgets code but just to make things fit using as little code as possible.
>
> In 10 years of wxWidgets use i never
> needed what you're trying to do, so i'm pretty sure there is another
> way to do it.
Sorry, but that's not the point here :) I don't want to discuss alternatives
but I just want to pass an arbitrary pointer to an event callback.
I have 15+ years experience in C so I generally know very well what
I'm doing. I just need a little help with C++ and wxWidgets related
stuff.
> wxWidgets is a C++ library after all and if you fight "against the
> system" all the time, you might not enjoy it very much ;)
> In an event handler you have event.GetId() which gives you the id of
> the control. And with event.GetEventObject() you get the control that
> created the event. E.g. for a wxButton event it would return a pointer
> to the button. These things are usually enough to react accordingly in
> the event handler.
Not in my case. I absolutely need to be able to pass an arbitrary pointer
to the callback.
Please let's not turn this into something different than it is: All I
was asking for was for an experienced C++ programmer to look over my
5 lines of code and say whether it's correct or not. Is that really
so difficult? :-) It's already been like around 10 mails now but they're
all rather unrelated. I really just want somebody who knows something
about wxWidgets and C++ to confirm that the code in my first mail
is correct or not. Nothing else, thanks :-)