Understanding Wine
DLL and Service Development in Wine
»Index
»Setup
»DLLs
»Services
»Windows
»svchost
»Links
»Notes
»Author
»Wine HQ

Error Codes

Error codes use a 32-bit encoding scheme:

0x 8 0 0 7 0 1 0 B
   | ----- -------
   |   |      |
   |   |      Error code
   |   Facility code
   Error status if highest bit set (other 3 are reserved)

A great place to look for information on errors is include/winerr.h. Be sure to look for both the hex value and the decimal value of the error code.

Component Life Cycle

DLL Registration

A COM DLL should register itself in the registry. This functionality is exposed through the DllRegisterServer and DllUnregisterServer functions that the DLL should expose. DLLs that implement these functions can be loaded and unloaded (from the registry) using the regsvr32 utility.

DLL Creation and Destruction

Calls to CoCreateInstance from client programs cause COM to examine the registry for the needed DLL and then call DllGetClassObject on the required DLL. DllGetClassObject typically uses a factory to create the new object.

Calls to CoCreateInstance request a location for the created object as in process, local, or remote. The CLSCTX_ALL flag is used to select any of these.

COM Services

Rumors say that COM services communicate using pipes.

StartServiceControlDispatcher is used to connect a service process to COM's service control manager (SCM). New threads are created to execute the ServiceMain functions passed in via the lpServiceTable formal. Since these are new threads, commands such as CoInitialize needs (?) to be called in the individual ServiceMain functions.

Individual ServiceMain functions call RegisterServiceCtrlHandler to associate an event handler with the service.

Status

Windows provides multiple facilities for observing and manipulating the status of various services. These include:

Start -> Control Panael -> Admin Tools -> Services (local)

for a GUI solution or net (often used as net start) from the command line.

General Structure

  • StartServiceCtrlDispatcher called from main function

  • Functionality to register the service using CreateService

  • Handler function to interact with messages coming in from the SCM

Registry

COM uses a registry to store and discover information about the host system. This includes discovering the DLL or executable that implements a given interface.

HKCR\AppID\<number> LocalServices = <service name>

HKCR\AppId\<service name> AppID = <number>

HKCR\CLSID\<number>\InProcServer32 @ = <dll name>

HKCR\Interface\<number> @ = <interface name>

HKLM\Software\Classes\AppID\<service name> AppID = <number>

HKLM\Software\Microsoft Windows NT\CurrentVersion\Svchost netsvs = {… BITS …}

HKLM\System\CurrentControlSet\Services\<service name> ImagePath = <path to service executable>

HKLM\System\CurrentControlSet\Services\<service name>\Parameters ServiceDll = <path to service dll>

svchost

At boot time, svchost loads the services grouped as values in its registry entry. The parameters of each value are the services to start. For example, the netsvs value under svnhost is noted to start a number of services including BITS.

Each service has a corresponding Services\<service name> entry in the registry that includes a Parameters value stating what program to run for the service.