我怎样才能在MFC中只检测磁卡读卡器。 [英] how can i detect only Magnetic card reader in MFC.

查看:77
本文介绍了我怎样才能在MFC中只检测磁卡读卡器。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个程序可以检测HID类USB whit这个命令



static const GUID GuidInterfaceList [] =

{0x4d1e55b2, 0xf16f,0x11Cf,{0x88,0xcb,0x00,0x11,0x11,0x00,0x00,0x30}},



但是我需要让它更多限制只用于磁性读卡器怎么做?意味着我不想让usb端口检测USB大容量存储或键盘,否则如果有人有想法让我知道请知道tnx

I have a programm that can detect HID class USB whit this command

static const GUID GuidInterfaceList[] =
{ 0x4d1e55b2, 0xf16f, 0x11Cf, { 0x88, 0xcb, 0x00, 0x11, 0x11, 0x00, 0x00, 0x30 } },

but i need to make it more limit only for Magnetic card reader How can do it ? means i don't want let usb port to detect USB Mass Storage or keyboard or else if anyone has idea let me know pls tnx

推荐答案

这是它,如果我可以帮助我解决任何问题。



Here it is, if I can help with any questions I will.

//===============================================================================
// USBHubArray.cpp : 
//===============================================================================
#include "stdafx.h"
#include "USBHubArray.h"

#include "..\\COMMON\\Registry.h"

#include <cfg.h>
#include <cfgmgr32.h>
#include <Dbt.h>
#include <setupapi.h>
#pragma comment (lib, "Setupapi.lib")

... Rest of class (CUSBHubArray) omitted for clarity

BOOL CUSBHubArray::Enum(CString* pError/*=NULL*/)
{
	Clear();

	// Create a HDEVINFO with all usb hubs.  We cannot use the DIGCF_PRESENT
	//  flag here, for some reason external usb hubs (which is the only thing 
	//  we care about at the moment) that are disabled will not be returned in 
	//  the results.  We will search for all registered usb hubs and then 
	//  determine their type (internal/external) and their state.

	HDEVINFO hDevices = SetupDiGetClassDevs(
		&GUID_DEVINT_USB_HUB, 
		0, 0, DIGCF_DEVICEINTERFACE);
    if(hDevices == INVALID_HANDLE_VALUE)
	{
		if(pError)
			*pError = GetLastWin32Error(
				_T("CUSBHubArray::Enum"), 
				_T("SetupDiGetClassDevs")
			);
		return FALSE;
	}

	// Make bigass buffer 
	const unsigned int PROP_BUFF_SZ = 1000;
	LPTSTR pBuffer = (LPTSTR)LocalAlloc(LPTR, PROP_BUFF_SZ);
	ASSERT(pBuffer);
	memset(pBuffer, 0, PROP_BUFF_SZ);

    // Enumerate 
	SP_DEVINFO_DATA did = {0};
	did.cbSize = sizeof(SP_DEVINFO_DATA);
	for(DWORD dw = 0; SetupDiEnumDeviceInfo(hDevices, dw, &did); dw++)
	{
		// Here we must go by the device name, the service name is 
		//   the same for all usb hubs; internal (root) and external
		if(!SetupDiGetDeviceRegistryProperty(hDevices, &did, 
			SPDRP_DEVICEDESC, NULL, (PBYTE)pBuffer, PROP_BUFF_SZ, NULL))
		{
			if(pError)
				*pError = GetLastWin32Error(
					_T("CUSBHubArray::Enum"), 
					_T("SetupDiGetDeviceRegistryProperty")
				);
			LocalFree(pBuffer);
			SetupDiDestroyDeviceInfoList(hDevices);
			return FALSE;
		}

		// Look for generic external hub name.  In the future this may need to be updated:
		//  if we must support another language or if the driver is updated/changed 
		if( (_tcsstr(pBuffer, _T("Standard-USB-Hub")) == 0) && // English OS
			(_tcsstr(pBuffer, _T("Generic USB Hub"))  == 0) )  // Deutsch OS
			continue;

		// Found a connected usb hub - read all properties that we need
		CUSBHubItem* pHubInfo = new CUSBHubItem;
		Add(pHubInfo);

		// See if device is present
		ULONG ulProblem = 0; // Present Disabled - 0x00000016 / Present Enabled - 0x00000000	
		ULONG ulStatus = 0;  //	Present Disabled - 0x01806400 / Present Enabled - 0x0180600a
		CONFIGRET cr = CM_Get_DevNode_Status(&ulStatus, &ulProblem, (DEVINST)did.DevInst, 0);
		if(cr & CR_FAILURE)
			pHubInfo->m_bPresent = false;

		// Check if device is disabled
		if(ulProblem & CM_PROB_DISABLED)
			pHubInfo->m_bDisabled = true;

		// Save device name
		pHubInfo->m_cstrDeviceName = pBuffer;
		memset(pBuffer, 0, PROP_BUFF_SZ);

		// Read device instance id
		if(!SetupDiGetDeviceInstanceId(hDevices, 
			&did, pBuffer, PROP_BUFF_SZ, NULL))
		{
			if(pError)
				*pError = GetLastWin32Error(
					_T("CUSBHubArray::Enum"), 
					_T("SetupDiGetDeviceInstanceId")
				);
			LocalFree(pBuffer);
			SetupDiDestroyDeviceInfoList(hDevices);
			return FALSE;
		}
		pHubInfo->m_cstrInstanceID = pBuffer;
		memset(pBuffer, 0, PROP_BUFF_SZ);

		// Read hardware id
		if(!SetupDiGetDeviceRegistryProperty(hDevices, &did, 
			SPDRP_HARDWAREID, NULL, (PBYTE)pBuffer, PROP_BUFF_SZ, NULL))
		{
			if(pError)
				*pError = GetLastWin32Error(
					_T("CUSBHubArray::Enum"), 
					_T("SetupDiGetDeviceRegistryProperty")
				);
			LocalFree(pBuffer);
			SetupDiDestroyDeviceInfoList(hDevices);
			return FALSE;
		}
		pHubInfo->m_cstrHardwareID = pBuffer;
		memset(pBuffer, 0, PROP_BUFF_SZ);

		// Figure out hub's registry key
		CString strRegKey = _T("SYSTEM\\CurrentControlSet\\Enum\\USB\\");
		strRegKey += pHubInfo->m_cstrInstanceID.Mid(4);
		pHubInfo->m_cstrRegKey = strRegKey;

		// Read ParentIdPrefix from registry
		CString strVal = _T("");
		GetRegStr(HKEY_LOCAL_MACHINE, strRegKey, 
			_T("ParentIdPrefix"), strVal.GetBuffer(MAX_PATH));
		strVal.ReleaseBuffer();
		pHubInfo->m_cstrPIDP = strVal;

		// Read symbolic name from registry
		CString strDPRegKey = strRegKey;
		strDPRegKey += _T("\\Device Parameters");
		GetRegStr(HKEY_LOCAL_MACHINE, strDPRegKey, 
			_T("SymbolicName"), strVal.GetBuffer(MAX_PATH));
		strVal.ReleaseBuffer();
		pHubInfo->m_cstrSymbName = strVal;

		// Read GE Number from registry
		pHubInfo->m_dwGENumber = GetRegDWORD(HKEY_LOCAL_MACHINE, strDPRegKey, _T("GENumber"), 0);
	}

	// Cleanup
	LocalFree(pBuffer);
	SetupDiDestroyDeviceInfoList(hDevices);

	return TRUE;
}


这篇关于我怎样才能在MFC中只检测磁卡读卡器。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆