On Tuesday, 15 May 2018 at 21:25:05 UTC, Andrei Alexandrescu wrote:
Hello, I was reviewing again DIP 1011 and investigated a library solution. That led to

https://gist.github.com/run-dlang/18845c9df3d73e45c945feaccfebfcdc

It builds on the opening examples in:

https://github.com/dlang/DIPs/blob/master/DIPs/DIP1011.md

I'm displeased at two aspects of the implementation:

* Perfect forwarding is tedious to implement: note that makeDelegate hardcodes void as the return type and (int, float) as parameter types. Ideally it should accept any parameters that the alias passes.

* Pass-by-alias and overloading interact poorly. Does anyone know how to refer by alias to one specific overload?


Thanks,

Andrei

While you are at it, could you add a linkage type that lets one specify marshaled member function callbacks for interfacing with callbacks in windows API?

In many windows callbacks they require specifying a function pointer for a standard winapi function. The problem is that we cannot pass methods of objects to windows functions wanting a callback since the methods use the calling convention of passing in object reference as the first parameter and expects that value to point to the object the method is acting in.

I have hacked together thunking using the standard methods to allow member functions but it is not pretty.

You can get more details of the problem here:

https://www.codeproject.com/Articles/16785/Thunking-in-Win-Simplifying-Callbacks-to-Non-sta


The idea would be to allow marking methods in a certain way which thunks them automatically for passing in to winapi callbacks almost as seamless as passing a static function.

It's a little tricky to do because the object reference as to be stored somewhere and retried correctly. In my hacked code I create a new function on the heap for each callback and store the object reference along side it. Inside the function it gets it's reference not from the hidden this parameter but from from the stored object value.

The real problem is the argument layout. Winapi will expect the first argument to be it's own but it stores the value in the object reference parameter. All these nuisances can be hidden by compiler magic.




Reply via email to