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

Posted on 2004-11-06
Last Modified: 2010-04-15
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:
DWORD            dwServiceType = SERVICE_WIN32,
            dwServiceState = SERVICE_STATE_ALL,
                      chBufSize = 30720,
            dwResumeHandle = 0,
            dwDesiredAccess = SC_MANAGER_ENUMERATE_SERVICE,
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 ?

Question by:jead99
    LVL 1

    Expert Comment

    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 need to do a similar thing as what I describe above...declare an array of char's and send in the address of that.
    LVL 6

    Accepted Solution


    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 :


    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.


    Featured Post

    IT, Stop Being Called Into Every Meeting

    Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

    Join & Write a Comment

    An Outlet in Cocoa is a persistent reference to a GUI control; it connects a property (a variable) to a control.  For example, it is common to create an Outlet for the text field GUI control and change the text that appears in this field via that Ou…
    Preface I don't like visual development tools that are supposed to write a program for me. Even if it is Xcode and I can use Interface Builder. Yes, it is a perfect tool and has helped me a lot, mainly, in the beginning, when my programs were small…
    Video by: Grant
    The goal of this video is to provide viewers with basic examples to understand and use for-loops in the C programming language.
    The goal of this video is to provide viewers with basic examples to understand and use switch statements in the C programming language.

    754 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    24 Experts available now in Live!

    Get 1:1 Help Now