Important:
This is retired content. This content is outdated and is no longer being maintained. It is provided as a courtesy for individuals who are still using these technologies. This content may contain URLs that were valid when originally published, but now link to sites or pages that no longer exist.
A version of this page is also available for
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

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

RegisterServicewill first load the DLL file specified in lpszLiband verify that it exports the xxx_Init, xxx_Deinit (Services.exe), and xxx_IOControl (Services.exe)functions. RegisterServicewill 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 lpszTypevalue are differentiated by different dwIndexvalues. These values must be unique for a given service. RegisterServicewill verify that no service has the same lpszTypeprefix and dwIndexvalue. If this is the case, it will fail and SetLastErrorto ERROR_DEVICE_IN_USE.

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

Note:
RegisterServiceis 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 ActivateServiceto load the service.

Requirements

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

See Also