API Export

This document discusses how to export a device driver API.

A driver can export its API to be used by other Kernel code by using IMPORT_C in the declaration and EXPORT_C in the definition. When the driver is built, these functions are exported to a .def file. The .def file is specific to the platform to which the driver is built.

// Kernel extension internal API
class DExController: public DBase
    {
    …
    void MyExAPI();
    …
    };

// Client interface API
class TExClientInterface
    {
    …
    // static function being exported, this API will go into def file 
    // generated while building
    IMPORT_C static void MyExAPI();
    …
    };

// Global instance of the object
DExController *ExController = NULL; 

// Implementation of the kernel extension's exported function
EXPORT_C void TExClientInterface::MyExAPI()
    {
    …
    ExController->MyExAPI();
    …
    }

Kernel extensions can also provide information to user programs by setting attributes that can be read through the system HAL (Hardware Abstration Layer) API. See Handler Implementation for more information on this.