<?xml version="1.0" encoding="UTF-8"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en-gb">
<link rel="self" type="application/atom+xml" href="https://forum.yubico.com/feed.php?f=3&amp;t=857" />

<title>Yubico Forum</title>
<subtitle>...visit our web-store at</subtitle>
<link href="https://forum.yubico.com/index.php" />
<updated>2012-09-03T18:35:27+01:00</updated>

<author><name><![CDATA[Yubico Forum]]></name></author>
<id>https://forum.yubico.com/feed.php?f=3&amp;t=857</id>
<entry>
<author><name><![CDATA[tekuru]]></name></author>
<updated>2012-09-03T18:35:27+01:00</updated>
<published>2012-09-03T18:35:27+01:00</published>
<id>https://forum.yubico.com/viewtopic.php?t=857&amp;p=3279#p3279</id>
<link href="https://forum.yubico.com/viewtopic.php?t=857&amp;p=3279#p3279"/>
<title type="html"><![CDATA[Re: COM API deviceInserted and deviceRemoved events not firi]]></title>

<content type="html" xml:base="https://forum.yubico.com/viewtopic.php?t=857&amp;p=3279#p3279"><![CDATA[
By the way I got around the notifications-only-via-checkbox thing by adding api.enableNotifications = ycNOTIFICATION_MODE.ycNOTIFICATION_ON; into the forms _Load() event handler.<p>Statistics: Posted by <a href="https://forum.yubico.com/memberlist.php?mode=viewprofile&amp;u=2149">tekuru</a> — Mon Sep 03, 2012 6:35 pm</p><hr />
]]></content>
</entry>
<entry>
<author><name><![CDATA[tekuru]]></name></author>
<updated>2012-09-03T18:06:36+01:00</updated>
<published>2012-09-03T18:06:36+01:00</published>
<id>https://forum.yubico.com/viewtopic.php?t=857&amp;p=3278#p3278</id>
<link href="https://forum.yubico.com/viewtopic.php?t=857&amp;p=3278#p3278"/>
<title type="html"><![CDATA[Re: COM API deviceInserted and deviceRemoved events not firi]]></title>

<content type="html" xml:base="https://forum.yubico.com/viewtopic.php?t=857&amp;p=3278#p3278"><![CDATA[
Thank you for that link. I noticed that the event handlers were actually:<br /><br /><div class="codetitle"><b>Code:</b></div><div class="codecontent">api.deviceInserted += new _IYubiClientEvents_deviceInsertedEventHandler(api_deviceInserted);<br />api.deviceRemoved += new _IYubiClientEvents_deviceRemovedEventHandler(api_deviceRemoved);</div><br />However they still didn't fire. <br /><br />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. <br /><br />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. <br /><br />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:<br /><br /><div class="codetitle"><b>Code:</b></div><div class="codecontent">        private void api_deviceRemoved()<br />        {<br />            this.Invoke((MethodInvoker)delegate<br />            {<br />                result.Text = &quot;Device Removed!! Boo...&quot;;<br />            });<br />        }<br /></div><br />Hope this helps someone.<br /><br />David<p>Statistics: Posted by <a href="https://forum.yubico.com/memberlist.php?mode=viewprofile&amp;u=2149">tekuru</a> — Mon Sep 03, 2012 6:06 pm</p><hr />
]]></content>
</entry>
<entry>
<author><name><![CDATA[Klas]]></name></author>
<updated>2012-09-03T08:24:16+01:00</updated>
<published>2012-09-03T08:24:16+01:00</published>
<id>https://forum.yubico.com/viewtopic.php?t=857&amp;p=3271#p3271</id>
<link href="https://forum.yubico.com/viewtopic.php?t=857&amp;p=3271#p3271"/>
<title type="html"><![CDATA[Re: COM API deviceInserted and deviceRemoved events not firi]]></title>

<content type="html" xml:base="https://forum.yubico.com/viewtopic.php?t=857&amp;p=3271#p3271"><![CDATA[
Hello,<br /><br />We've used that functionality in the settingspanel for the YubiKey Logon for Windows, you can have a look at it at: <!-- m --><a class="postlink" href="https://github.com/Yubico/yubico-windows-auth/blob/master/YubiSettings/YubiSettings/YubiSettings.cs#L129">https://github.com/Yubico/yubico-window ... gs.cs#L129</a><!-- m --><br /><br />/klas<p>Statistics: Posted by <a href="https://forum.yubico.com/memberlist.php?mode=viewprofile&amp;u=2019">Klas</a> — Mon Sep 03, 2012 8:24 am</p><hr />
]]></content>
</entry>
<entry>
<author><name><![CDATA[tekuru]]></name></author>
<updated>2012-09-03T01:32:56+01:00</updated>
<published>2012-09-03T01:32:56+01:00</published>
<id>https://forum.yubico.com/viewtopic.php?t=857&amp;p=3269#p3269</id>
<link href="https://forum.yubico.com/viewtopic.php?t=857&amp;p=3269#p3269"/>
<title type="html"><![CDATA[COM API deviceInserted and deviceRemoved events not firing]]></title>

<content type="html" xml:base="https://forum.yubico.com/viewtopic.php?t=857&amp;p=3269#p3269"><![CDATA[
Hello, <br /><br />I seem to be having an issue with the COM API using C# .NET, specifically with the deviceInserted and deviceRemoved events. I am aware that I need to set the notification mode to asynchronous, which I do, however my code is never called when I insert and remove my YubiKey. The Test MFC C++ app does however work properly. Below is my code, stripped down to just the essentials. This is a WinForms project:<br /><br /><div class="codetitle"><b>Code:</b></div><div class="codecontent">    public partial class Form1 : Form<br />    {<br />        public YubiClientAPILib.YubiClient api;<br /><br />        public Form1()<br />        {<br />            InitializeComponent();<br /><br />            api = new YubiClientAPILib.YubiClient();<br />            api.enableNotifications = YubiClientAPILib.ycNOTIFICATION_MODE.ycNOTIFICATION_ON;<br /><br />            // removal/insertion events<br />            api.deviceInserted += this.api_deviceInserted;<br />            api.deviceRemoved += this.api_deviceRemoved;<br />        }<br /><br />        private void api_deviceRemoved()<br />        {<br />            MessageBox.Show(&quot;Device Removed!! Boo...&quot;);<br />        }<br /><br />        private void api_deviceInserted()<br />        {<br />            MessageBox.Show(&quot;Device Inserted!! Wahoo&quot;);<br />        }<br />   }<br /></div><br /><br />It is Yubico Client API 1.0 Type Library, version 1.0.0.0, x64 with Visual Studio 2010. I just downloaded the API installer today, 02 Sep 2012. <br /><br />See anything obvious? Unfortunately the provided C# example does not include this functionality so I couldn't use that as a reference. <br /><br />Thank you for any help, <br />David<p>Statistics: Posted by <a href="https://forum.yubico.com/memberlist.php?mode=viewprofile&amp;u=2149">tekuru</a> — Mon Sep 03, 2012 1:32 am</p><hr />
]]></content>
</entry>
</feed>