Search code examples
c++visual-studio-2012typedef

Defining a function using a function typedef in C++


I am implementing a service in Windows. VisualStudio 2012 has the following function typedef:

typedef VOID WINAPI SERVICE_MAIN_FUNCTIONW (
    DWORD dwNumServicesArgs,
    LPWSTR *lpServiceArgVectors
);

There is also a function pointer typedef:

typedef VOID (WINAPI *LPSERVICE_MAIN_FUNCTIONW)(
    DWORD   dwNumServicesArgs,
    LPWSTR  *lpServiceArgVectors
);

How do I define a function with this function signature, using the typedef?


Solution

  • You don't need (and cannot) use typedef in a function definition. To make a service main function, just write:

    VOID WINAPI SvcMain( DWORD dwNumServicesArgs, LPWSTR *lpServiceArgVectors )
    {
        // ...
    }
    

    LPSERVICE_MAIN_FUNCTIONW is used internally by Windows to call every service start point. Generally, you need function pointer typedef to call, and not to define a function.