Everything I do results in some problem, I've tried malloc but then converting the strings resulted in my program becoming corrupted.

Heres the code:

auto EnumServices()
{

auto schSCManager = OpenSCManager(null, null, SC_MANAGER_ALL_ACCESS);
    if (NULL == schSCManager)
    {
        print("OpenSCManager failed (%d)\n", GetLastError());
return null; // Why can't we return a null? Surely we don't have to cast a null in to a typeof null?
    }
        
        import core.stdc.stdlib;
        
        DWORD dwBytesNeeded, dwCount, lpResumeHandle, resume;

auto servicesType = (SERVICE_DRIVER | SERVICE_FILE_SYSTEM_DRIVER | SERVICE_KERNEL_DRIVER | SERVICE_WIN32 | SERVICE_WIN32_OWN_PROCESS | SERVICE_WIN32_SHARE_PROCESS);


        
        ENUM_SERVICE_STATUS_PROCESS[5000] services;
auto res = SVC.EnumServicesStatusExA(schSCManager, SC_ENUM_TYPE.SC_ENUM_PROCESS_INFO, servicesType, SERVICE_STATE_ALL, cast(ubyte*)services.ptr, 5000*ENUM_SERVICE_STATUS_PROCESS.sizeof, &dwBytesNeeded, &dwCount, &resume, cast(const(char)*)null);
        
        
        for(int i = 0; i < dwCount; i++)
        {
                auto s = services[i].lpServiceName;
                writeln(*s);                            
        }


        return services;
}

Reply via email to