A virtual device uses the Begin_Service_Table and End_Service_Table macros to declare its services. The macros mark the start and end of a list containing the names of the services and optionally the names of the segments containing the services. The declaration must be made in the same file as the virtual device declaration (that is, in the file containing the Declare_Virtual_Device macro) and must be preceded with the definition of a device-specific symbol. The following example shows service table declaration for the sample virtual device, VSAMPLED:
Create_VSAMPLED_Service_Table equ 1
Begin_Service_Table VSAMPLED
VSAMPLED_Service VSAMPLED_Get_Version, LOCAL
VSAMPLED_Service VSAMPLED_Service_1
VSAMPLED_Service VSAMPLED_Service_2, VxD_ICODE
End_Service_Table VSAMPLED
In this example, the Create_VSAMPLED_Service_Table symbol, defined just before the service table declaration, directs the Begin_Service_Table macro to create a service table for VSAMPLED. Once the declaration starts, the VSAMPLED_Service macro actually declares the services. This required macro is created by the Begin_Service_Table macro, and is only available within the service table declaration. The name of each service must exactly match the service's defined name, that is, the name given with the BeginProc macro.
When declaring a service, the LOCAL option must be given after the service name if the service is defined in the same source file containing the service table declaration. In other words, the service table automatically declares a service as an external service unless the LOCAL option is given. In the previous example, the VSAMPLED_Get_Version service is defined in the same file containing the service table.
Similarly, a segment name must be given after the service name if the service is not defined in the VxD_CODE segment. In the previous example, the VSAMPLE_Service_2 service is defined in the VxD_ICODE segment.
The order in which services are declared is important. The first declared service for a virtual device must be the Get_Version service. (This service clears the carry flag and returns with the virtual device's version number in the AX register.) Also, any new services added to the virtual device must be declared at the end of the table (or in explicitly reserved slots in the table). Since the VMM relies on the order of the services in the table to correctly link to the services, inserting a new service in the middle of the table requires that all virtual devices using the virtual device's service be rebuilt. For convenience, the service table declaration should be placed in an include file so that other virtual devices can import the services by including the file rather than recreating the declaration.