I have code which checks if smart card is inserted or removed:
void checkCard(void *p)
{
//...
while(true)
{
if (ReaderState1.dwEventState & SCARD_STATE_EMPTY)
{
// Smart card removed, call disconnect
disconnectCard(cardHandle);
}
else
{
// Smart card inserted do smth else
}
}
}
In main
I call above thread:
int main()
{
...
if(establichContext(_hSC) == true)
{
// Start thread
_beginthread(checkCard, 0, NULL);
// Sleep
Sleep(1000000); // or some other logic which halts program for some time
// Disconnect from card and release context
disconnectCard(cardHandle);
releaseContext(_hSC);
}
}
My problem is if smart card was already removed - by the first code snippet (checkCard
function), calling disconnectCard
- second time as in main
, fails. How would you deal with such situation?
disconnectCard
- just uses SCardDisconnect method inside )http://msdn.microsoft.com/en-us/library/windows/desktop/aa379475(v=vs.85).aspx)