On Thursday, 13 July 2017 at 01:15:46 UTC, FoxyBrown wrote:
auto EnumServices()

I wouldn't use auto here. The reason you get mismatch types on return here since you don't return consistent types inside.

        ENUM_SERVICE_STATUS_PROCESS[5000] services;

Are you sure you are getting the same A vs W version there? You explicitly call the A version of the function, but do not specify it here.

                auto s = services[i].lpServiceName;

Like the other user above said, you should be treating that like a C string anyway. Use printf or fromStringz or slice it yourself... just make sure you tend to char vs wchar like above.

        return services;

That's kinda hideous, returning the entire buffer by value. I do NOT recommend you attempt to slice and dup though, since the win32 function uses space at the end of the buffer to store the strings referenced by the structs.

Ideally, you'd avoid returning this thing at all and just use it locally. Perhaps pass a callback function/delegate that takes each item as you iterate through.

Reply via email to