ISensorClassExtension::Initialize method

The ISensorClassExtension::Initialize method initializes the sensor class extension object.

Syntax


HRESULT Initialize(
  [in] IUnknown *pWdfDeviceUnknown,
  [in] IUnknown *pSensorDriverUnknown
);

Parameters

pWdfDeviceUnknown [in]

IUnknown pointer for the driver class that implements the IWDFDevice interface.

pSensorDriverUnknown [in]

IUnknown pointer for the object that implements the ISensorDriver callback interface.

Return value

This method returns an HRESULT. Possible values include, but are not limited to, one of the following values. See Remarks.

Return codeDescription
S_OK

The method succeeded.

E_POINTER

The argument was NULL or the IWDFDevice interface is missing..

HRESULT_FROM_WIN32(ERROR_ALREADY_EXISTS)

The class extension is already initialized.

HRESULT_FROM_WIN32(ERROR_ALREADY_INITIALIZED)

The class extension is already initialized.

HRESULT_FROM_WIN32(ERROR_NOT_FOUND)

The WPD_OBJECT_ID for the sensor is not valid.

 

Remarks

First, create the sensor class extension by calling the COM CoCreateInstance method, and then call Initialize. We recommend that you perform these initialization steps when called by UMDF in IPnpCallbackHardware::OnPrepareHardware. After Initialize returns, the driver must be ready to receive callbacks from the sensor class extension. The sensor class extension calls ISensorDriver::OnGetSupportedSensorObjects during initialization. Your driver must be ready to return values for all required properties and data fields before it calls Initialize.

Because the class extension calls your driver during initialization, this method can also return HRESULTs that your driver returns from ISensorDriver::OnGetSupportedSensorObjects.

Examples

The following example code shows a snippet from an implementation of OnPrepareHardware that creates and initializes the sensor class extension object.


// Create an instance of the class that implements ISensorDriver.
hr = CComObject<CSensorCallback>::CreateInstance(&m_pSensorCallback);

if(SUCCEEDED(hr))
{
 m_pSensorCallback->AddRef();

 CComPtr<IUnknown> spUnknown;
   // Query the callback class for its IUnknown pointer.
    hr = m_pSensorCallback->QueryInterface(IID_IUnknown, (void**)&spUnknown);

    if( SUCCEEDED(hr))
    {
        // Create the class extension object.
        hr = CoCreateInstance(CLSID_SensorClassExtension,
                              NULL,
                              CLSCTX_INPROC_SERVER,
                              __uuidof(ISensorClassExtension),
                              (VOID**)&m_pClassExtension);
 
        if(SUCCEEDED(hr))
        {
            // Initialize the class extension.
            hr = m_pClassExtension->Initialize(pWdfDevice, spUnknown);
        }
    }
}

Requirements

Minimum supported client

Windows 7

Minimum supported server

None supported

Target platform

Version

Available in Windows 7.

Header

Sensorsclassextension.h

Library

SensorsClassExtension.lib

See also

ISensorClassExtension::Uninitialize

 

 

Send comments about this topic to Microsoft

Show: