2.4 Constructing the Driver Object

Each time an application driver is run, the DirXML engine obtains a new instance of the DriverObject. A Java driver is constructed by calling a no-argument constructor. A C++ driver is constructed by calling the CreateDriver function that is exported from the driver module ( such as a DLL, NLM, or shared library).

The DirXML engine starts the driver. The DirXML driver stores the name of its executable in one of the attributes of its DirXML-Driver object. If the driver is a Java application, it stores the name in the DirXML-JavaModule attribute. If the driver is a native module (DLL, NLM, or shared library), the driver stores the name in the DirXML-NativeModule attribute.

2.4.1 Java Constructor

The following sample code illustrates how to create the constructor for the driver.

  public SkeletonDriverShim ()
  

2.4.2 CreateDriver Function for C++

Your driver module must export a factory method for creating a new instance of your driver object. The factory method must be exported by name.

The CreateDriver function has the following syntax:

     DriverShim * CreateDriver(
        void);
  

On Win32 platforms, one of three names may be used (due to compiler name generation): "CreateDriver", "_CreateDriver", or "_CreateDriver@0". The following sample code illustrates how to create the function for the Win32 platforms.

  extern "C" CSKELETONDRIVER_API DriverShim * METHOD_CALL
  CreateDriver(void)
  {
     return new CSkeletonDriver();
  }
  

On Netware the function name must consist of "CreateDriver" with the uppercase name of the NLM appended to it. For example if the driver NLM is named COOLDRVR.NLM then the exported name must be "CreateDriverCOOLDRVR"). The following code illustrates how to create the function for the NetWare platform.

  extern "C" DriverShim *
  CreateDriverSKELDRVR()
  {
     DriverShim   * shim = new NW_DriverShim();
     //add to our housekeeping stuff
     addShim(shim);
     return   shim;
  }