Thank you for that link. I noticed that the event handlers were actually:
Code:
api.deviceInserted += new _IYubiClientEvents_deviceInsertedEventHandler(api_deviceInserted);
api.deviceRemoved += new _IYubiClientEvents_deviceRemovedEventHandler(api_deviceRemoved);
However they still didn't fire.
This got me experimenting a bit, and I discovered that the COM api only enables notifications if you enable the notifications via a button or checkbox after the app has loaded. What I mean is, in my initial code example I was setting the notification mode inside the forms constructor, however I was never getting notifications.
I then noticed that in both the test MFC app and in your link for the logon app, you were enabling the notifications via a check box. So I did the same, in my code I removed the enableNotifications statement from the constructor and put it into the event handler for the checkBox's checkChanged event, and suddenly the events were firing.
There was still one problem though, the event handlers are running on a different thread than the UI thread, and if I paid attention to the debug log I saw an illegal operation exception as I was trying to set my result label from a different thread. To get around this I used:
Code:
private void api_deviceRemoved()
{
this.Invoke((MethodInvoker)delegate
{
result.Text = "Device Removed!! Boo...";
});
}
Hope this helps someone.
David