how to use \\?PnP?\Notification to get the card status change when calling SCardGetStatusChange API using a card reader.

Siddesh 26 Reputation points
2024-01-03T05:50:04.09+00:00

I want to detect card insert/remove event in a card reader without having to poll using VC++.

 

When i use \?PnP?\Notification in SCardGetStatusChange API i get the result as 
0x80100009 - the specified reader name is not recognised and the EventState always remains 0

 

Also can someone point to some samples on how i can listen to \?PnP?\Notification event and proceed accordingly

Windows API - Win32
Windows API - Win32
A core set of Windows application programming interfaces (APIs) for desktop and server applications. Previously known as Win32 API.
2,731 questions
C++
C++
A high-level, general-purpose programming language, created as an extension of the C programming language, that has object-oriented, generic, and functional features in addition to facilities for low-level memory manipulation.
3,850 questions
0 comments No comments
{count} votes

Accepted answer
  1. Jeanine Zhang-MSFT 10,531 Reputation points Microsoft Vendor
    2024-01-03T08:01:55.4166667+00:00

    Hello,

    Welcome to Microsoft Q&A!

    I want to detect card insert/remove event in a card reader without having to poll using VC++.

    You could try to check whether the rgReaderStates contains SCARD_STATE_EMPTY or SCARD_STATE_PRESENT. The SCardGetStatusChange function blocks execution until the current availability of the cards in a specific set of readers changes. So, if you want to monitor the reader during program execution, you may need to call it in a separate thread.

    According to the doc:SCardGetStatusChangeA function

    To be notified of the arrival of a new smart card reader, set the szReader member of a SCARD_READERSTATE structure to "\?PnP?\Notification", and set all of the other members of that structure to zero.

    If you set the szReader member to "\?PnP?\Notification", each member of SCARD_READERSTATE structure must be initialized to zero and then set to specific values as necessary.

    Could you please provide a sample to help us reproduce the issue?

    Thank you.

    Jeanine


    If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".

    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    1 person found this answer helpful.
    0 comments No comments

0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.