81 lines
2.2 KiB
C
81 lines
2.2 KiB
C
|
|
#pragma once
|
||
|
|
#include <windows.h>
|
||
|
|
#include <devguid.h> // for GUID_DEVCLASS_CDROM etc
|
||
|
|
#include <setupapi.h>
|
||
|
|
#include <cfgmgr32.h> // for MAX_DEVICE_ID_LEN, CM_Get_Parent and CM_Get_Device_ID
|
||
|
|
#include <hidsdi.h>
|
||
|
|
#include <Hidclass.h>
|
||
|
|
#include <string>
|
||
|
|
#include "okClr.h"
|
||
|
|
#include <msclr\auto_gcroot.h>
|
||
|
|
|
||
|
|
namespace OkReadBadge
|
||
|
|
{
|
||
|
|
|
||
|
|
public class BadgeUnmanaged
|
||
|
|
{
|
||
|
|
|
||
|
|
private:
|
||
|
|
LPOVERLAPPED Overlapped;
|
||
|
|
msclr::auto_gcroot<BadgeMessageHandler^> m_clr;
|
||
|
|
|
||
|
|
public:
|
||
|
|
// TODO: Add your methods for this class here.
|
||
|
|
wchar_t * DevicePath;
|
||
|
|
int DeviceType;
|
||
|
|
BYTE buffer[100];
|
||
|
|
DWORD bread;
|
||
|
|
|
||
|
|
bool nextCSN = false;
|
||
|
|
bool nextSite = false;
|
||
|
|
bool nextCode = false;
|
||
|
|
bool nextFinish = false;
|
||
|
|
char Res [100];
|
||
|
|
|
||
|
|
|
||
|
|
static bool CALLBACK Message(int err, LPARAM param)
|
||
|
|
{
|
||
|
|
//m_clr.Result = gcnew buffer
|
||
|
|
BadgeUnmanaged *bu = static_cast<BadgeUnmanaged *>((void *)param);
|
||
|
|
if (err == 0) {
|
||
|
|
byte l = bu->buffer[2];
|
||
|
|
char *r = (char *)&bu->buffer[4];
|
||
|
|
r[l] = 0;
|
||
|
|
if (bu->nextCSN) {
|
||
|
|
memcpy_s(bu->Res, 100, r, l + 1); bu->nextCSN = false; }
|
||
|
|
else if (bu->nextSite) {
|
||
|
|
strncat_s(bu->Res, (const char *)r, l); bu->nextSite = false; }
|
||
|
|
else if (bu->nextCode) {
|
||
|
|
strncat_s(bu->Res, (const char *)r, l); bu->nextCode = false; bu->nextFinish = true;
|
||
|
|
}
|
||
|
|
else if (!strncmp("csn:", r, 4)) {
|
||
|
|
memset(bu->Res, 0, sizeof(bu->Res));
|
||
|
|
bu->nextCSN = true; bu->nextFinish = bu->nextCode = bu->nextSite = false ;
|
||
|
|
}
|
||
|
|
else if (!strncmp("site:", r, 5)) { bu->nextSite = true; }
|
||
|
|
else if (!strncmp("code:", r, 5)) { bu->nextCode = true; }
|
||
|
|
else if (!strncmp(";", r, 1)) {
|
||
|
|
strncat_s(bu->Res, r, 1);
|
||
|
|
bu->nextCode = bu->nextSite = bu->nextCSN = false;
|
||
|
|
if (bu->nextFinish) {
|
||
|
|
bu->nextFinish = false;
|
||
|
|
}
|
||
|
|
}
|
||
|
|
bu->m_clr->Result = gcnew String(r);
|
||
|
|
}
|
||
|
|
else {
|
||
|
|
if (bu->nextCSN | bu->nextFinish | bu->nextCode | bu->nextSite | bu->nextCSN )
|
||
|
|
bu->m_clr->Result = gcnew String(bu->Res);
|
||
|
|
else
|
||
|
|
bu->m_clr->Result = String::Empty;
|
||
|
|
}
|
||
|
|
return bu->m_clr->OnMessage((int)err);
|
||
|
|
}
|
||
|
|
BadgeUnmanaged(BadgeMessageHandler^ clr);
|
||
|
|
void GetDeviceUSB(std::wstring vid, std::wstring pid, std::wstring pid2);
|
||
|
|
int read();
|
||
|
|
};
|
||
|
|
}
|
||
|
|
|
||
|
|
|