RegisterService

A version of this page is also available for

Windows Embedded CE 6.0 R3

4/8/2010

This function creates a new instance of a service.

Syntax

HANDLE RegisterService(
  LPCWSTR lpszType,
  DWORD dwIndex,
  LPCWSTR lpszLib,
  DWORD dwInfo
);

Parameters

  • lpszType
    [in] Pointer to the string that contains the three-letter service prefix code.
  • dwIndex
    [in] Specifies the service index number between 0 and 9.
  • lpszLib
    [in] Pointer to the string that contains the name of the DLL file that contains the service.
  • dwInfo
    [in] Specifies the argument passed during the call to the service's exposed xxx_Init (Services.exe) function.

Return Value

A handle to the service is returned on success. A NULL value is returned on failure. For extended error information, call GetLastError.

Remarks

RegisterService can be used to either load an unloaded service into memory or create a new instance of a service already loaded.

RegisterService will first load the DLL file specified in lpszLib and verify that it exports the xxx_Init, xxx_Deinit (Services.exe), and xxx_IOControl (Services.exe) functions. RegisterService will fail with ERROR_FILE_NOT_FOUND if the DLL file cannot be loaded and ERROR_INVALID_FUNCTION if the file does not export the required functions.

Varying instances of a service running from the same DLL and with the same lpszType value are differentiated by different dwIndex values. These values must be unique for a given service. RegisterService will verify that no service has the same lpszType prefix and dwIndex value. If this is the case, it will fail and SetLastError to ERROR_DEVICE_IN_USE.

Services.exe will then call the xxx_Init function and pass it the value stored in dwInfo. If the service returns a value of zero, Services.exe will fail and SetLastError to ERROR_OPEN_FAILED. Otherwise, it will store the return value of xxx_Init and pass it as a context value at a later time when calling another function of the service such as xxx_Deinit and xxx_IOControl.

Note

RegisterService is available for use by normal applications only. To avoid trust issues, it is recommended that you use the registry to set up your service, then call ActivateService to load the service.

Requirements

Header service.h
Library coredll.lib
Windows Mobile Windows Mobile Version 5.0 and later

See Also

Reference

xxx_Init (Services.exe)
xxx_Deinit (Services.exe)
xxx_IOControl (Services.exe)

Concepts

Services.exe Registry Settings

Other Resources

Services.exe