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;

    return true;
}

void main() {
    EnumWindows(&callback, 0);

    writeln(hWndList);
}

================================================================

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 delegate.

================================================================

import core.sys.windows.windows: EnumWindows;
import std.stdio: writeln;

void main() {
    void*[] hWndList;

    EnumWindows((void* hWnd, long /* lParams */ ) nothrow {
        hWndList ~= hWnd; return true;
    }, 0);

    writeln(hWndList);
}

================================================================

I'm not going to even paste the compiler error because I am very clearly going about this the wrong way.

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.

Thanks.

Reply via email to