Problem in catching the events.
I am working on providing support to the audio devices. I have a problem in receiving the events fired by a COM component. Please see the following source code.
class CDeviceManager
{
Â…
Â…
};
HRESULT CdeviceManager::InitializeDevice()
{
// Get the interface to the DeviceControl.
HRESULT hr = CoCreateInstance(__uuidof(DeviceControl), NULL, CLSCTX_ALL, IID_IDPMControl,(void **)&m_pControl);
if FAILED(hr)
{
return hr;
}
//Create the event sink and register it with the control to
//receive the events from the device
// control.
m_pEventSink = new CEventSink(this);
hr = m_pEventSink->DispEventAdvise(m_pControl);
if(FAILED(hr))
{
return hr;
}
// Initialize the device
hr = m_pControl->Initialize();
if(FAILED(hr))
{
return hr;
}
// I need to display this message box in order to receive the
// events. If this message is not displayed, the events wonÂ’t
// received unless CdeviceManager is Dialog (or window) class and
// the dialog is displayed. Either way it is problem as my
// application is not designed to show the messages.
::MessageBoxEx(HWND_DESKTOP,
"please click ‘OK’ to download files",
"Application Message", MB_OK|MB_TOPMOST , NULL);
}
My job is to download the files from the audio device connected to the USB port. The vendor of the device has provided a COM component called, DeviceControl. This component has implemented a connection point (dual interface) called _DDeviceEvents. Some of these events include, DeviceConnected, DeviceReady, DeviceDisconnected etc. I need to ensure that the device is in the “Ready” state before downloading the files from the device. For this I am using a class “CEventSink” which was copied from the sample application (a dialog based application) provided by the vendor. CEventSink is defined like this.
class CEventSink : public IDispEventImpl<1,
CEventSink,
&DIID__DDeviceEvents,
&LIBID_CONTROLLib, 1, 0>
But mine is not a dialog-based application. It is a simple NT based service, which runs in the background. When it detects that a device was connected to the USB port, it instantiates the DeviceControl and gets an interface pointer to IDeviceControl. Through this interface, the pEventSink registers with the DeviceControl to receive the events like this.
pEventSink->DispEventAdvise(m_pDpmControl);
Then the DeviceControl is initialized like this.
pIDeviceControl->Initialize();
Soon after this statement, the functions CEventSink:eviceConnected() and CEventSink:eviceReady() should be called by the DeviceControl. So I get to know about the status of the device. But these functions are never called. All these statements were put in a simple C++ class. If make this class a dialog class, I receive the events or If I call the MessageBox(), after pIDeviceControl->Initialize(), I am able to catch the events.
Please let me know how I can catch these events without implementing a window class or without showing a window.
Thanks and regards,
Mohan.
I am working on providing support to the audio devices. I have a problem in receiving the events fired by a COM component. Please see the following source code.
class CDeviceManager
{
Â…
Â…
};
HRESULT CdeviceManager::InitializeDevice()
{
// Get the interface to the DeviceControl.
HRESULT hr = CoCreateInstance(__uuidof(DeviceControl), NULL, CLSCTX_ALL, IID_IDPMControl,(void **)&m_pControl);
if FAILED(hr)
{
return hr;
}
//Create the event sink and register it with the control to
//receive the events from the device
// control.
m_pEventSink = new CEventSink(this);
hr = m_pEventSink->DispEventAdvise(m_pControl);
if(FAILED(hr))
{
return hr;
}
// Initialize the device
hr = m_pControl->Initialize();
if(FAILED(hr))
{
return hr;
}
// I need to display this message box in order to receive the
// events. If this message is not displayed, the events wonÂ’t
// received unless CdeviceManager is Dialog (or window) class and
// the dialog is displayed. Either way it is problem as my
// application is not designed to show the messages.
::MessageBoxEx(HWND_DESKTOP,
"please click ‘OK’ to download files",
"Application Message", MB_OK|MB_TOPMOST , NULL);
}
My job is to download the files from the audio device connected to the USB port. The vendor of the device has provided a COM component called, DeviceControl. This component has implemented a connection point (dual interface) called _DDeviceEvents. Some of these events include, DeviceConnected, DeviceReady, DeviceDisconnected etc. I need to ensure that the device is in the “Ready” state before downloading the files from the device. For this I am using a class “CEventSink” which was copied from the sample application (a dialog based application) provided by the vendor. CEventSink is defined like this.
class CEventSink : public IDispEventImpl<1,
CEventSink,
&DIID__DDeviceEvents,
&LIBID_CONTROLLib, 1, 0>
But mine is not a dialog-based application. It is a simple NT based service, which runs in the background. When it detects that a device was connected to the USB port, it instantiates the DeviceControl and gets an interface pointer to IDeviceControl. Through this interface, the pEventSink registers with the DeviceControl to receive the events like this.
pEventSink->DispEventAdvise(m_pDpmControl);
Then the DeviceControl is initialized like this.
pIDeviceControl->Initialize();
Soon after this statement, the functions CEventSink:eviceConnected() and CEventSink:eviceReady() should be called by the DeviceControl. So I get to know about the status of the device. But these functions are never called. All these statements were put in a simple C++ class. If make this class a dialog class, I receive the events or If I call the MessageBox(), after pIDeviceControl->Initialize(), I am able to catch the events.
Please let me know how I can catch these events without implementing a window class or without showing a window.
Thanks and regards,
Mohan.