I have simplified your code, and removed all the non essential parts, to the following, which lists the (basic) service information. You just need to add some prettier formatting as necessary.
#include<stdio.h>
#include<stdlib.h>
#include<Windows.h>
#include<winsvc.h>
int main()
{
SC_HANDLE scHandle = OpenSCManager(NULL, NULL, SC_MANAGER_ENUMERATE_SERVICE);
if (scHandle == 0)
{
printf("Handle not got\n");
exit(1);
}
else
{
printf("handle success\n");
}
DWORD bytesNeeded = 0; DWORD servicesReturnedCount = 0;
DWORD resumeHandle = 0;
do
{
printf("Enter do\n");
if (!EnumServicesStatusEx(
scHandle,
SC_ENUM_PROCESS_INFO,
SERVICE_TYPE_ALL,
SERVICE_STATE_ALL,
NULL,
0,
&bytesNeeded,
&servicesReturnedCount,
&resumeHandle,
NULL))
{
if (ERROR_MORE_DATA == GetLastError())
{
LPENUM_SERVICE_STATUS_PROCESS services = (LPENUM_SERVICE_STATUS_PROCESS)malloc(bytesNeeded);
if ((EnumServicesStatusEx(
scHandle,
SC_ENUM_PROCESS_INFO,
SERVICE_TYPE_ALL,
SERVICE_STATE_ALL,
(PBYTE)services,
bytesNeeded,
&bytesNeeded,
&servicesReturnedCount,
NULL,
NULL))) {
for (DWORD i = 0; i < servicesReturnedCount; ++i)
{
printf("%s %s\n", services[i].lpServiceName, services[i].lpDisplayName);
}
}
else
{
break;
}
}
else
{
break;
}
}
} while (resumeHandle != 0);
CloseServiceHandle(scHandle);
getc(stdin);
}