Exemple #1
0
HRESULT
CVDevDevice::Initialize ( 
                         _In_ IWDFDriver           * FxDriver,
                         _In_ IWDFDeviceInitialize * FxDeviceInit)
/*++

    Routine Description:
        This method initializes the device callback object and creates the
        partner device object.
        
    Arguments:
        FxDeviceInit - the settings for this device.

    Return Value:
        HRESTULT indication of success or failure

--*/
{
    IWDFDevice * fxDevice = NULL;

    HRESULT hr = S_OK;

    Enter();

    FxDeviceInit->SetLockingConstraint (None);
    FxDeviceInit->SetFilter();

    {
        IUnknown * unknown = this->QueryIUnknown ();

        hr = FxDriver->CreateDevice (FxDeviceInit, unknown, &fxDevice);

        unknown->Release ();
    }

    if (SUCCEEDED (hr)) 
    {
        m_FxDevice = fxDevice;

        //
        // We can release the reference as the lifespan is tied to the 
        // framework object.
        //
        fxDevice->Release();
    }

    ExitHR(hr);
    return hr;
}
HRESULT
CMyDevice::Initialize(
    _In_ IWDFDriver           * FxDriver,
    _In_ IWDFDeviceInitialize * FxDeviceInit
    )
/*++
 
  Routine Description:

    This method initializes the device callback object and creates the
    partner device object.

    The method should perform any device-specific configuration that:
        *  could fail (these can't be done in the constructor)
        *  must be done before the partner object is created -or-
        *  can be done after the partner object is created and which aren't 
           influenced by any device-level parameters the parent (the driver
           in this case) might set.

  Arguments:

    FxDeviceInit - the settings for this device.

  Return Value:

    status.

--*/
{
    IWDFDevice *fxDevice = NULL;

    HRESULT hr = S_OK;

    //
    // TODO: If you're writing a filter driver then indicate that here. 
    //
    // FxDeviceInit->SetFilter();
    //

    //
    // Set no locking unless you need an automatic callbacks synchronization
    //

    FxDeviceInit->SetLockingConstraint(None);

    //
    // TODO: Any per-device initialization which must be done before 
    //       creating the partner object.
    //


    //
    // Create a new FX device object and assign the new callback object to 
    // handle any device level events that occur.
    //

    //
    // QueryIUnknown references the IUnknown interface that it returns
    // (which is the same as referencing the device).  We pass that to 
    // CreateDevice, which takes its own reference if everything works.
    //

    if (SUCCEEDED(hr)) 
    {
        IUnknown *unknown = this->QueryIUnknown();

        hr = FxDriver->CreateDevice(FxDeviceInit, unknown, &fxDevice);

        unknown->Release();
    }

    //
    // If that succeeded then set our FxDevice member variable.
    //

    if (SUCCEEDED(hr)) 
    {
        m_FxDevice = fxDevice;

        //
        // Drop the reference we got from CreateDevice.  Since this object
        // is partnered with the framework object they have the same 
        // lifespan - there is no need for an additional reference.
        //

        fxDevice->Release();
    }

    return hr;
}
Exemple #3
0
HRESULT
CMyDevice::Initialize(
    __in IWDFDriver           * FxDriver,
    __in IWDFDeviceInitialize * FxDeviceInit
    )
/*++
 
  Routine Description:

    This method initializes the device callback object and creates the
    partner device object.

    The method should perform any device-specific configuration that:
        *  could fail (these can't be done in the constructor)
        *  must be done before the partner object is created -or-
        *  can be done after the partner object is created and which aren't 
           influenced by any device-level parameters the parent (the driver
           in this case) might set.

  Arguments:

    FxDeviceInit - the settings for this device.

  Return Value:

    status.

--*/
{
    IWDFDevice *fxDevice = NULL;

    HRESULT hr = S_OK;

    
    //
    // TODO: If you're writing a filter driver then indicate that here. 
    //
    // FxDeviceInit->SetFilter();
    //

    //
    // Set no locking unless you need an automatic callbacks synchronization
    //

    FxDeviceInit->SetLockingConstraint(None);

    //
    // Only one driver in the stack can be the Power policy owner (PPO).
    //
    // NOTE: If we want UMDF to be the PPO we also ask WinUsb.sys 
    // to not set itself as the PPO by setting the
    // WinUsbPowerPolicyOwnershipDisabled key through 
    // an AddReg in the INF.
    //     
#if defined(_NOT_POWER_POLICY_OWNER_)
    FxDeviceInit->SetPowerPolicyOwnership(FALSE);        
#else
    FxDeviceInit->SetPowerPolicyOwnership(TRUE);        
#endif
    
    //
    // TODO: Any per-device initialization which must be done before 
    //       creating the partner object.
    //

    //
    // Create a new FX device object and assign the new callback object to 
    // handle any device level events that occur.
    //

    //
    // QueryIUnknown references the IUnknown interface that it returns
    // (which is the same as referencing the device).  We pass that to 
    // CreateDevice, which takes its own reference if everything works.
    //

    if (SUCCEEDED(hr)) 
    {
        IUnknown *unknown = this->QueryIUnknown();

        hr = FxDriver->CreateDevice(FxDeviceInit, unknown, &fxDevice);

        unknown->Release();
    }

    //
    // If that succeeded then set our FxDevice member variable.
    //

    if (SUCCEEDED(hr)) 
    {
        //
        // Drop the reference we got from CreateDevice.  Since this object
        // is partnered with the framework object they have the same 
        // lifespan - there is no need for an additional reference.
        //
        
        fxDevice->Release();

        IWDFDevice2 *fxDevice2 = NULL;
        
        HRESULT hrQI = fxDevice->QueryInterface(__uuidof(IWDFDevice2), (void**) &fxDevice2);  
        
        WUDF_TEST_DRIVER_ASSERT(SUCCEEDED(hrQI) && fxDevice2);

        m_FxDevice = fxDevice2;
        
        //
        // Drop the reference we got from QueryInterface(). Since this object
        // is partnered with the framework object they have the same 
        // lifespan - there is no need for an additional reference.
        //
        
        fxDevice2->Release();        
    }

    return hr;
}