| ▲ | pjmlp 10 hours ago |
| Or I don't know, just use C++ lambdas instead? |
|
| ▲ | LegionMammal978 8 hours ago | parent [-] |
| You can't turn a capturing C++ lambda into a WNDPROC, which is an ordinary function pointer. You'd still have to ferry the lambda via a context pointer, which is what this blog post and the other solutions in the comments are all about. |
| |
| ▲ | pjmlp 7 hours ago | parent [-] | | You kind of can, that is one of their design points, naturally you need to move the context into the body and know what to cast back from. I guess I need to prove a point on my Github during next week. | | |
| ▲ | LegionMammal978 6 hours ago | parent | next [-] | | If you mean that you can call a C++ lambda from a static C callback via a context pointer, of course you can do that, it's not very mind-boggling. Rust FFI libraries similarly have to do that trick all the time to turn a closure into a C callback. The primary problem with WNDPROC is how to get that context pointer in the first place, which is the part that OP and everyone in the comments are talking about. | |
| ▲ | rovingeye 7 hours ago | parent | prev [-] | | I assume by "move the context into the body" you mean using GetWindowLongPtr? Why not just use a static wndproc at that point? | | |
| ▲ | pjmlp 5 hours ago | parent [-] | | I mean using a static C++ lambda that moves the context into the lambda body via capture specifier. C++ lambdas are basically old style C++ functors that are compiled generated, with the calling address being the operator(). | | |
|
|
|