Re: Use nested functions as callbacks with Windows API functions?

2018-10-02 Thread John Chapman via Digitalmars-d-learn
On Monday, 1 October 2018 at 20:27:43 UTC, spikespaz wrote: Of course there is nothing wrong with defining each callback as a separate function, but then comes the issue of naming them. I also don't like the way it makes my code look. I think the best you can do is something like this: ---

Re: Use nested functions as callbacks with Windows API functions?

2018-10-02 Thread Boris-Barboris via Digitalmars-d-learn
On Monday, 1 October 2018 at 23:07:29 UTC, spikespaz wrote: The problem with the code you have is that the callback needs to be extern (Windows). I don't know how to do that with a "lambda". Neither do I actually. Apparently it is impossible. Best I could squeeze out was this:

Re: Use nested functions as callbacks with Windows API functions?

2018-10-01 Thread spikespaz via Digitalmars-d-learn
On Monday, 1 October 2018 at 21:03:24 UTC, Boris-Barboris wrote: On Monday, 1 October 2018 at 20:27:43 UTC, spikespaz wrote: I was hoping I could use something more akin to JavaScript's syntax: (void* hWnd, long) => {}. I tried this but I'm getting errors with the signature, it says the

Re: Use nested functions as callbacks with Windows API functions?

2018-10-01 Thread spikespaz via Digitalmars-d-learn
On Monday, 1 October 2018 at 21:03:24 UTC, Boris-Barboris wrote: On Monday, 1 October 2018 at 20:27:43 UTC, spikespaz wrote: I was hoping I could use something more akin to JavaScript's syntax: (void* hWnd, long) => {}. I tried this but I'm getting errors with the signature, it says the

Re: Use nested functions as callbacks with Windows API functions?

2018-10-01 Thread Boris-Barboris via Digitalmars-d-learn
On Monday, 1 October 2018 at 20:27:43 UTC, spikespaz wrote: I was hoping I could use something more akin to JavaScript's syntax: (void* hWnd, long) => {}. I tried this but I'm getting errors with the signature, it says the function is a delegate and apparently Windows API can't accept a

Use nested functions as callbacks with Windows API functions?

2018-10-01 Thread spikespaz via Digitalmars-d-learn
I have the following code, this works. import core.sys.windows.windows: EnumWindows; import std.stdio: writeln; void*[] hWndList; extern (Windows) int callback(void* hWnd, long /* lParams */ ) nothrow { hWndList ~= hWnd;