Device callback object isn't referenced by the framework



Hi,

I've been studying about developing a driver using WDF (UMDF in my case) for
a while using "Developing Drivers with the Windows Driver Foundation" and the
examples that comes with the DDK.

In those examples (e.g. fx2_driver and echo), I've noticed that after an
object creation a call to Release() is made on it, so that the framework, who
has taken a reference to this object, will be responsible for it's deletion,
am I right?

My problem is that I found a situation where this doesn't happen. My device
callback object doesn't implement any of the interfaces (except IUnknown),
because I want the framework to manage pnp events, so by the time of
creation, I noticed that the fx won't take a reference to my device object as
it does when I implement an interface, such as IPnpCallbackHardware.

Here is where it happens:
// CMyDevice::Initialize
IUnknown *unknown = this->QueryIUnknown();

// When my device obj doesn't implement any interfaces except
IUnknown
// the fx won't take a reference to it
hr = FxDriver->CreateDevice(FxDeviceInit, unknown, &fxDevice);

unknown->Release();
// ...

So if I call Release() after the initilization and configuration of my
device callback object, it will delete itself ! But my queues take a
reference to this object (a weak reference as it is named on the example) and
my driver crashes when they try to reference my device callback object
(obviously).

Here is where it calls Release()
// CMyDriver::OnDeviceAdd
// ...
if (SUCCEEDED(hr))
{
hr = device->Configure();
}
if (NULL != device)
{
device->Release();
}
// ...

I've solved this by implementing IPnpCallback with dummy methods (they just
return S_OK), but I'd like to know how can I do it the best way:
- should I avoid weak references in my queues? But then they would be
responsible for the deletion of my device callback object, wouldn't they?
- should I do as I did implementing IPnpCallback?
- or should I be aware that my object doesn't implement an interface that
the fx requires and don't call Release() after it's creation?

Thanks in advance

Thiago Figueredo
.



Relevant Pages

  • Re: Device callback object isnt referenced by the framework
    ... I've been studying about developing a driver using WDF ... callback object doesn't implement any of the interfaces, ... I noticed that the fx won't take a reference to my device object ... my driver crashes when they try to reference my device callback object ...
    (microsoft.public.development.device.drivers)
  • Re: Unresolved Externals creating driver
    ... usbpdi.obj: error LNK2019: unresolved external symbol ... > an identical driver, under a different name. ... > I get in this vicious circle of putting in a reference to a library, ... > having the build complain about multiply defined symbols. ...
    (microsoft.public.windowsce.platbuilder)
  • Re: [PATCH 1/1] : hwmon - new chip driver for TI ADS7828 A-D
    ... revised patch. ... driver, which seems to work well with the hardware I'm working with (a ... Operate with the internal 2.5v reference - set to N for external reference ...
    (Linux-Kernel)
  • Re: [PATCH] fix rmmod sbp2 hang in 2.6.7
    ... Is the 'sg' driver loaded. ... When I load my SCSI HBA driver, ... It's because sg also got a reference. ... rmmod 'sg' then the rmmod of st frees up too. ...
    (Linux-Kernel)