如何在 C++ 中侦听智能卡插入和移除事件?
我想监听智能购物车的插入和删除事件...该应用程序适用于 Windows,智能卡使用 x.509 证书。我使用的读卡器是标准读卡器,可插入大多数新笔记本电脑,您也可以购买它们用于 USB 使用。
我发现的一件事是: cryptware.it/apidoc/scapi/index.html 但这不可能是唯一的方法,我只是想知道我的选择......
有谁知道最好的方法是什么?
提前致谢!
I want to listen for the insert and remove event of a smart cart... The application is for windows and the smart card is using x.509 certificates. The reader I use is standard card readers that is inserted in most new laptops and you can also buy them for usb use..
One thing I have found is:
cryptware.it/apidoc/scapi/index.html
but it cant be the only way and I just wanted to know my options...
Does anyone know what's the best way to do this?
Thanks in advance!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
Windows API 具有此功能:
然后您可以检查
rgReaderStates
是否包含SCARD_STATE_EMPTY
或SCARD_STATE_PRESENT
。请阅读此处的详细信息: MSDN 说明严格来说,它不是事件驱动的但它会阻止执行,直到发生更改。因此,通过创建一个单独的线程来循环调用它,您可以轻松地自己生成事件。
The Windows API has this function:
You can then check if the
rgReaderStates
containsSCARD_STATE_EMPTY
orSCARD_STATE_PRESENT
. Read the details here: MSDN descriptionIt is strictly speaking not event-driven but it blocks execution until a change happened. So by creating a separate thread that calls this in a loop, you can easily generate an event yourself.
一个例子。
这应该合并到以时间间隔(1 秒)运行该函数的线程函数中。线程函数应该使用它并向应用程序发送驱动程序已更改的通知。
警告:丑陋的代码。请以此为例并根据您的需要进行改进。
A example.
This should be incorporated in thread function which runs this function at a time interval (1 second). The thread function should use this and sends a notification to the application that the driver has changed.
WARNING: UGLY CODE. PLEASE USE THIS AS AN EXAMPLE AND IMPROVE IT AS YOU SEE FIT.