Partager via


Loading a Bluetooth Extension Layer (Windows CE 5.0)

Send Feedback

With the installable device driver architecture you must compile the extension layer as a DLL. To use the extension layer the application must load and then create a driver instance by using standard stream driver procedures.

The L2capapi sample located in the %_WINCEROOT%\Public\Common\Oak\Drivers\Bluetooth\Sample\L2capapi directory, shows how an application can use the L2capdev extension layer DLL.

To load the extension layer from your application

  1. Register the DLL by calling the RegisterDevice function.

    The following example code shows a function L2CAPLoad, that is defined in the L2capapi sample. This function registers the L2CAP extension layer, L2capdev.dll by calling RegisterDevice and sets the appropriate registry key values.

    int L2CAPLoad (void) 
    {
      HANDLE hDevice = RegisterDevice (L"L2C", 0, L"l2capdev.dll", 0);
      if (hDevice) 
      {
        HKEY hk;
        if (ERROR_SUCCESS == RegOpenKeyEx (HKEY_BASE, L"Software\\Microsoft\\Bluetooth", 0, KEY_READ, &hk)) 
        {
          RegSetValueEx (hk, L"l2capdev_handle", 0, REG_DWORD, (LPBYTE)&hDevice, sizeof(hDevice));
          RegCloseKey (hk);
        }
      }
      return hDevice != NULL ? ERROR_SUCCESS : ERROR_SERVICE_NOT_ACTIVE;
    }
    
  2. To create an instance of the driver, call the CreateFile function.

    The following example code shows a function Initialize, that is declared in the L2capapi sample. This function creates an instance of the driver by calling CreateFile.

    HANDLE hDev = INVALID_HANDLE_VALUE;
    int Initialize (void) 
    {
      if (hDev != INVALID_HANDLE_VALUE)
      return TRUE;
      hDev = CreateFile (L"L2C0:", 
        GENERIC_READ | GENERIC_WRITE, FILE_SHARE_READ | FILE_SHARE_WRITE,
        NULL, OPEN_EXISTING, 0, NULL);
      return (hDev != INVALID_HANDLE_VALUE) ? TRUE : FALSE;
    }
    

See Also

Creating a Bluetooth Stack Extension Layer | Bluetooth OS Design Development | Host Controller Interface | How to Develop and Load a Bluetooth HCI Stack Extension Layer

Send Feedback on this topic to the authors

Feedback FAQs

© 2006 Microsoft Corporation. All rights reserved.