Code:
int __stdcall RFID_Handler(CPhidgetRFIDHandle RFID, void *userptr,
unsigned char *buf)
{
wsprintf(rfId,L"%x%x%x%x%x%x%x%x%x%x\n",
buf[0]/16,buf[0]%16,buf[1]/16,buf[1]%16, buf[2]/16,buf[2]%16,
buf[3]/16,buf[3]%16, buf[4]/16,buf[4]%16);
result = 1;
return 0;
}
// This is our entrypoint, where the PollGina calls us
POLLIB_API void pollFunction(LPTSTR loginUsername,LPTSTR
loginPassword,LPTSTR loginDomain) {
WCHAR *username = NULL, *password = NULL, *domain = NULL;
CPhidgetRFIDHandle RFID = 0;
CPhidgetRFID_create(&RFID);
CPhidget_set_OnAttach_Handler((CPhidgetHandle)RFID,
RFID_AttachHandler, NULL);
CPhidget_set_OnDetach_Handler((CPhidgetHandle)RFID,
RFID_DetachHandler, NULL);
CPhidget_set_OnError_Handler((CPhidgetHandle)RFID,
RFID_ErrorHandler, NULL);
CPhidget_open ((CPhidgetHandle)RFID, -1);
// Clear any existing rfid data
memset(rfId,0,sizeof(rfId));
CPhidgetRFID_setAntennaOn(RFID, true);
// Set the callback for read events
CPhidgetRFID_set_OnTag_Handler(RFID, RFID_Handler, NULL);
// Set the output state to 3
CPhidgetRFID_setOutputState(RFID, 3, true);
//CPhidgetRFID_setLEDOn(RFID, true);
usleep (100);
//while (1)
//{
// if (result) break;
//}
// If an id was read
if(_tcslen(rfId)) {
// And it does NOT match the last used one
if(lastUsed) {
if(wcscmp(rfId,lastUsed) == 0) {
// This is the same one as last time, ignore it
goto cleanup;
}
}
// Strip trailing \n that phidgets puts in...
if(wcsstr(rfId,L"\n")) {
*(wcsstr(rfId,L"\n")) = '\0';
}
username = AnsiToUnicode("DennisYan");
password = AnsiToUnicode("dennisbar");
domain = AnsiToUnicode("");
// Username is required, the rest are optional, put the data in
the buffers provided by PollGina
if(username) {
wsprintf(loginUsername,L"%s",username);
if(password) {
wsprintf(loginPassword,L"%s",password);
}
if(domain) {
wsprintf(loginDomain,L"%s",domain);
}
}
}
// Cleanup after ourselves.. free memory we've allocated, and
leave
cleanup:
if(username) {
free(username);
username = NULL;
}
if(password) {
free(password);
password = NULL;
}
if(domain) {
free(domain);
domain = NULL;
}
// Close the reader
CPhidget_close ((CPhidgetHandle)RFID);
// Delete our context
CPhidget_delete((CPhidgetHandle )RFID);
}
then i compile with