• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 276
  • Last Modified:

n00b question about declaring a variable be a pointer to a structure

I'm new to C and trying to mess around with some of the functions from windows.h

I'm trying out this one:

BOOL EnumServicesStatusEx(
  SC_HANDLE hSCManager,
  SC_ENUM_TYPE InfoLevel,
  DWORD dwServiceType,
  DWORD dwServiceState,
  LPBYTE lpServices,
  DWORD cbBufSize,
  LPDWORD pcbBytesNeeded,
  LPDWORD lpServicesReturned,
  LPDWORD lpResumeHandle,
  LPCTSTR pszGroupName
);

I've declared my variables as:
SC_ENUM_TYPE       InfoLevel = SC_ENUM_PROCESS_INFO;
DWORD            dwServiceType = SERVICE_WIN32,
            dwServiceState = SERVICE_STATE_ALL,
                      chBufSize = 30720,
            dwServicesReturned,
            dwBytesNeeded,
            dwResumeHandle = 0,
            dwDesiredAccess = SC_MANAGER_ENUMERATE_SERVICE,
            dwProcID;
LPCTSTR            pszGroupName = NULL;

But i'm having a problem with the lpServices variable which should be a pointer to the buffer that receives the status information.

My question is how do I specify a variable to contain this information ?

Thanks.
0
jead99
Asked:
jead99
1 Solution
 
gckcmcCommented:
so lpServices is of type LPBYTE, which means pointer to a byte.  therefore, above your function call, declare a variable of type LPBYTE, such as:

LPBYTE lpbyteFoo;

then pass the address of lpbyteFoo to the function call.  (&lpbyteFoo)

note, your pszGroupName is Null, so anything writing to that will crash...you need to do a similar thing as what I describe above...declare an array of char's and send in the address of that.
0
 
stsanzCommented:
1)

lpServices is a pointer to the buffer that receives the information about the enumerated service on output.
The buffer will contain a number of ENUM_SERVICE_STATUS_PROCESS structures.
You need to declare a buffer big enough to hold the returned information. Then pass the address of this buffer to the function call.

For example :

BYTE Services[1000] ;

and pass &Services as lpServices parameter.

If the buffer is not big enough, the function call will fail, GetLastError will return ERROR_MORE_DATA,
and you'll get the size needed in pcbBytesNeeded parameter.

For more detail on how to know the exact size needed and what the buffer contains, see :
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dllproc/base/enumservicesstatusex.asp

2)

You can pass NULL to pszGroupName. In that case, there is no filter on services group name, and you get an enumeration
of all services whatever group they belong to.

0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Tackle projects and never again get stuck behind a technical roadblock.
Join Now