亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频

? 歡迎來到蟲蟲下載站! | ?? 資源下載 ?? 資源專輯 ?? 關于我們
? 蟲蟲下載站

?? usbhidiocdlg.cpp

?? USB 編程必備.詳細說明USB原理及控制方法.
?? CPP
?? 第 1 頁 / 共 2 頁
字號:
				NULL);

			//Open a handle to the device.

			/*
			API function: CreateFile
			Returns: a handle that enables reading and writing to the device.
			Requires:
			The DevicePath in the detailData structure
			returned by SetupDiGetDeviceInterfaceDetail.
			*/

			DeviceHandle=CreateFile \
				(detailData->DevicePath, \
				GENERIC_READ|GENERIC_WRITE, \
				FILE_SHARE_READ|FILE_SHARE_WRITE, \
				NULL, \
				OPEN_EXISTING, \
				0, \
				NULL);

			DisplayLastError("CreateFile: ");

			/*
			API function: HidD_GetAttributes
			Requests information from the device.
			Requires: the handle returned by CreateFile.
			Returns: a HIDD_ATTRIBUTES structure containing
			the Vendor ID, Product ID, and Product Version Number.
			Use this information to decide if the detected device is
			the one we're looking for.
			*/

			//Set the Size to the number of bytes in the structure.
			Attributes.Size = sizeof(Attributes);

			Result = HidD_GetAttributes \
				(DeviceHandle, \
				&Attributes);
			
			DisplayLastError("HidD_GetAttributes: ");
			
			//Is it the desired device?
			MyDeviceDetected = FALSE;
			

			if (Attributes.VendorID == VendorID)
			{
				if (Attributes.ProductID == ProductID)
				{
					//Both the Product and Vendor IDs match.
					MyDeviceDetected = TRUE;
					DisplayData("Device detected");
					//Get the device's capablities.
					GetDeviceCapabilities();
					//Use this handle for writing reports.
					WriteHandle=DeviceHandle;
					//ReadFile is a blocking call, 
					//so get another handle for another thread for reading reports.
					ReadHandle=CreateFile \
						(detailData->DevicePath, \
						GENERIC_READ|GENERIC_WRITE, \
						FILE_SHARE_READ|FILE_SHARE_WRITE, \
						NULL, \
						OPEN_EXISTING, \
						0, \
						NULL);
					DisplayLastError("CreateFile for Read Handle: ");

					/*
					Create a thread for reading reports from the device.
					ReadFile is a blocking call, so it's called in a separate program thread.
					This keeps the main program thread from hanging while waiting for a
					report from the device.
					In CreateThread, StaticIO_Thread is a static member that accepts
					the "this" pointer and casts it to a pointer to the ReadReport routine, 
					which does the ReadFile.
					*/

					ThreadHandle = CreateThread \
						(NULL, \
						0, \
						(LPTHREAD_START_ROUTINE)StaticIO_Thread, \
						this, \
						0, \
						&ThreadID);
					
					if (ThreadHandle == NULL)
						CloseHandle(ThreadHandle);

					DisplayLastError("CreateThread: ");

				} //if (Attributes.ProductID == ProductID)
				else
					//The Product ID doesn't match.
					CloseHandle(DeviceHandle);
			} //if (Attributes.VendorID == VendorID)
			else
				//The Vendor ID doesn't match.
				CloseHandle(DeviceHandle);

		//Free the memory used by the detailData structure (no longer needed).
		free(detailData);
		}  //if (Result != 0)
		else
			//SetupDiEnumDeviceInterfaces returned 0, so there are no more devices to check.
			LastDevice=TRUE;

		//If we haven't found the device yet, and haven't tried every available device,
		//try the next one.
		MemberIndex = MemberIndex + 1;

	} //do
	while ((LastDevice == FALSE) && (MyDeviceDetected == FALSE));

	if (MyDeviceDetected == FALSE)
		DisplayData("Device not detected");

	SetupDiDestroyDeviceInfoList(hDevInfo);
	DisplayLastError("SetupDiDestroyDeviceInfoList");

	return MyDeviceDetected;
}

void CUsbhidiocDlg::GetDeviceCapabilities()
{
	//Get the Capabilities structure for the device.
	PHIDP_PREPARSED_DATA	PreparsedData;

	/*
	API function: HidD_GetPreparsedData
	Returns: a pointer to a buffer containing the information about the device's capabilities.
	Requires: A handle returned by CreateFile.
	There's no need to access the buffer directly,
	but HidP_GetCaps and other API functions require a pointer to the buffer.
	*/

	HidD_GetPreparsedData \
		(DeviceHandle, \
		&PreparsedData);
	DisplayLastError("HidD_GetPreparsedData: ");

	/*
	API function: HidP_GetCaps
	Learn the device's capabilities.
	For standard devices such as joysticks, you can find out the specific
	capabilities of the device.
	For a custom device, the software will probably know what the device is capable of,
	and the call only verifies the information.
	Requires: the pointer to the buffer returned by HidD_GetPreparsedData.
	Returns: a Capabilities structure containing the information.
	*/
	
	HidP_GetCaps \
		(PreparsedData, \
		&Capabilities);
	DisplayLastError("HidP_GetCaps: ");

	//Display the capabilities
	CString ValueToDisplay;
	ValueToDisplay.Format("%s%X", "Usage Page: ", Capabilities.UsagePage);
	DisplayData(ValueToDisplay);
	ValueToDisplay.Format("%s%d", "Input Report Byte Length: ", Capabilities.InputReportByteLength);
	DisplayData(ValueToDisplay);
	ValueToDisplay.Format("%s%d", "Output Report Byte Length: ", Capabilities.OutputReportByteLength);
	DisplayData(ValueToDisplay);
	ValueToDisplay.Format("%s%d", "Feature Report Byte Length: ", Capabilities.FeatureReportByteLength);
	DisplayData(ValueToDisplay);
	ValueToDisplay.Format("%s%d", "Number of Link Collection Nodes: ", Capabilities.NumberLinkCollectionNodes);
	DisplayData(ValueToDisplay);
	ValueToDisplay.Format("%s%d", "Number of Input Button Caps: ", Capabilities.NumberInputButtonCaps);
	DisplayData(ValueToDisplay);
	ValueToDisplay.Format("%s%d", "Number of InputValue Caps: ", Capabilities.NumberInputValueCaps);
	DisplayData(ValueToDisplay);
	ValueToDisplay.Format("%s%d", "Number of InputData Indices: ", Capabilities.NumberInputDataIndices);
	DisplayData(ValueToDisplay);
	ValueToDisplay.Format("%s%d", "Number of Output Button Caps: ", Capabilities.NumberOutputButtonCaps);
	DisplayData(ValueToDisplay);
	ValueToDisplay.Format("%s%d", "Number of Output Value Caps: ", Capabilities.NumberOutputValueCaps);
	DisplayData(ValueToDisplay);
	ValueToDisplay.Format("%s%d", "Number of Output Data Indices: ", Capabilities.NumberOutputDataIndices);
	DisplayData(ValueToDisplay);
	ValueToDisplay.Format("%s%d", "Number of Feature Button Caps: ", Capabilities.NumberFeatureButtonCaps);
	DisplayData(ValueToDisplay);
	ValueToDisplay.Format("%s%d", "Number of Feature Value Caps: ", Capabilities.NumberFeatureValueCaps);
	DisplayData(ValueToDisplay);
	ValueToDisplay.Format("%s%d", "Number of Feature Data Indices: ", Capabilities.NumberFeatureDataIndices);
	DisplayData(ValueToDisplay);

	//No need for PreparsedData any more, so free the memory it's using.
	HidD_FreePreparsedData(PreparsedData);
	DisplayLastError("HidD_FreePreparsedData: ") ;
}

void CUsbhidiocDlg::ReadAndWriteToDevice()
{
	//If we haven't done so already, find the device and learn its capabilities.
	//Then send a report and request a report.
	//The test device firmware (usbhidio) adds 1 to each byte received in an OUT report
	//and sends the results back in the next IN report.

	//Clear the List Box (optional).
	//m_ResultsList.ResetContent();

	//Don't attempt anything if a previous transfer hasn't completed.
		{
		DisplayData("***HID Test Report***");
		DisplayCurrentTime();

		//If the device hasn't been detected already, look for it.
		if (DeviceDetected==FALSE)
			DeviceDetected=FindTheHID();
		
		if (DeviceDetected==TRUE)
			{

				//Write a report to the device.
				WriteReport();

				//Get the latest report read from the device and display it.
				DisplayInputReport();

			} // (EndIf: if DeviceDetected == True)
		}

}

DWORD CUsbhidiocDlg::StaticIO_Thread(LPVOID Param)
	{
		//Used in creating a thread for ReadFiles.
		//Accepts the "this" pointer and casts it to a pointer to ReadReport.
		if (Param != NULL)
			return ((CUsbhidiocDlg*)Param)->ReadReport();
		else
			return -1;
	}

DWORD WINAPI CUsbhidiocDlg::ReadReport()
{
	CString	ByteToDisplay = "";
	ULONG	InputReportLength = 0;
	CString	MessageToDisplay = "";
	ULONG	Result;
	
	//Read a report from the device.

	InputReportLength=Capabilities.InputReportByteLength;

	do
	{
		/*
		ReadFile
		Returns:
		A report in InputReport.
		The number of bytes actually read in BytesRead.
		Requires: 
		A device handle returned by CreateFile.
		The report length returned by HidP_GetCaps in Capabilities.InputReportByteLength.
		*/

		Result = ReadFile \
			(ReadHandle, \
			InputReport, \
			Capabilities.InputReportByteLength, \
			&BytesRead, \
			NULL);

		ActualBytesRead = BytesRead;

		if (Result == 0)
		{
			//The ReadFile failed, so close the handle, display a message,
			//and set DeviceDetected to FALSE so the next attempt will look for the device.
			CloseHandle(ReadHandle);
			DisplayData("Can't read from device");
			DeviceDetected = FALSE;
		}
	}
	//Exit the loop if the device is no longer detected or the user has clicked the close button.
	while ((DeviceDetected == TRUE) && (ApplicationActive == TRUE));

    return 0;
}

void CUsbhidiocDlg::WriteReport()
{
	//Send a report to the device.

	DWORD	BytesWritten = 0;
	INT		Index =0;
	CHAR	OutputReport[3];
	ULONG	Result;
	CString	strBytesWritten = "";

	//The first byte is the report number.
	OutputReport[0]=0;

	//Can set the other report values here, or get them from the combo boxes.
	//OutputReport[1]=33;
	//OutputReport[2]=6;
	//OutputReport[3]=15;

	//Get the bytes to send from the combo boxes.
	
	//If Autoincrement is checked, increment the selection.
	if (m_cbutAutoIncrement.GetCheck()>0)
	{
		Index=m_cboByteToSend0.GetCurSel();
		Index=Index+1;
		m_cboByteToSend0.SetCurSel(Index);
	}

	if (m_cbutAutoIncrement.GetCheck()>0)
	{
		Index=m_cboByteToSend1.GetCurSel();
		Index=Index+1;
		m_cboByteToSend1.SetCurSel(Index);
	}

	//Get the values from the combo boxes.
	OutputReport[1]=m_cboByteToSend0.GetCurSel();
	OutputReport[2]=m_cboByteToSend1.GetCurSel();

	/*
	WriteFile
	Sends a report to the device.
	Returns: success or failure.
	Requires:
	The device handle returned by CreateFile.
	The Output Report length returned by HidP_GetCaps,
	A report to send.
	*/

	Result = WriteFile \
		(DeviceHandle, \
		OutputReport, \
		Capabilities.OutputReportByteLength, \
		&BytesWritten, \
		NULL);

	if (Result == 0)
	{
		//The WriteFile failed, so close the handle, display a message,
		//and set DeviceDetected to FALSE so the next attempt will look for the device.
		CloseHandle(DeviceHandle);
		DisplayData("Can't write to device");
		DeviceDetected = FALSE;
	}
	
	//Display the result of the API call and the report bytes.
	DisplayLastError("WriteFile: ");
	strBytesWritten.Format("%s%d", "Bytes Written: ", BytesWritten); 
	DisplayData(strBytesWritten);
}

/*
Display-related routines
*/

void CUsbhidiocDlg::DisplayInputReport()
{
	USHORT	ByteNumber;
	CString	MessageToDisplay = "";
	CHAR	ReceivedByte;
	//Display the number of bytes read.
	MessageToDisplay.Format("%s%d", "Number of Bytes Read: ", ActualBytesRead); 
	DisplayData(MessageToDisplay);
	
	//Display the received data in the log and the Bytes Received List boxes.
	//Start at the top of the List Box.
	m_BytesReceived.ResetContent();
	
	//Step through the received bytes and display each.
	for (ByteNumber=0; ByteNumber < Capabilities.InputReportByteLength; ByteNumber++)
	{
		//Get a byte.
		ReceivedByte = InputReport[ByteNumber];
		//Display it.
		DisplayReceivedData(ReceivedByte);
	}
}

void CUsbhidiocDlg::DisplayCurrentTime()
{
	//Get the current time and date and display them in the log List Box.
	CTime curTime = CTime::GetCurrentTime();
	CString CurrentTime = curTime.Format( "%H:%M:%S, %B %d, %Y" );
	DisplayData(CurrentTime);
}

void CUsbhidiocDlg::DisplayData(CString cstrDataToDisplay)
{
	//Display data in the log List Box
	USHORT	Index;
	Index=m_ResultsList.InsertString(-1, (LPCTSTR)cstrDataToDisplay);
	ScrollToBottomOfListBox(Index);
}

void CUsbhidiocDlg::DisplayLastError(CString Operation)
{
	//Display a message and the last error in the log List Box. 
	LPVOID lpMsgBuf;
	USHORT Index = 0;
	CString	strLastError = "";
	FormatMessage( 
		FORMAT_MESSAGE_ALLOCATE_BUFFER | 
		FORMAT_MESSAGE_FROM_SYSTEM | 
		FORMAT_MESSAGE_IGNORE_INSERTS,
		NULL,
		GetLastError(),
		MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
		(LPTSTR) &lpMsgBuf,
		0,
		NULL 
	);

	//Display the last error.
	strLastError = Operation + (LPCTSTR)lpMsgBuf; 
	//Trim CR/LF from the error message.
	strLastError.TrimRight(); 
	Index = m_ResultsList.InsertString(-1, strLastError);
	ScrollToBottomOfListBox(Index);
	LocalFree(lpMsgBuf); 
}

void CUsbhidiocDlg::DisplayReceivedData(char ReceivedByte)
{
	//Display data received from the device.
	CString	strByteRead;
	//Convert the value to a 2-character Cstring.
	strByteRead.Format("%02X", ReceivedByte);
	strByteRead = strByteRead.Right(2); 
	//Display the value in the Bytes Received List Box.
	m_BytesReceived.InsertString(-1, strByteRead);
	//Display the value in the log List Box (optional).
	//MessageToDisplay.Format("%s%s", "Byte 0: ", strByteRead); 
	//DisplayData(MessageToDisplay);
}

void CUsbhidiocDlg::OnChangeResults() 
{
	// TODO: If this is a RICHEDIT control, the control will not
	// send this notification unless you override the CDialog::OnInitDialog()
	// function and call CRichEditCtrl().SetEventMask()
	// with the ENM_CHANGE flag ORed into the mask.
	
	// TODO: Add your control notification handler code here
}

void CUsbhidiocDlg::ScrollToBottomOfListBox(USHORT Index)
{
	/* 
	Scroll to the bottom of the list box. 
	To do so, add a line and set it as the current selection,
	possibly scrolling the window.
	Then deselect the line, 
	leaving the list box scrolled to the bottom with nothing selected.
	*/

	m_ResultsList.SetCurSel( Index );
	m_ResultsList.SetCurSel( -1 );
}

/*
Misc. routines.
*/

void CUsbhidiocDlg::OnTimer(UINT nIDEvent) 
{
	//The timer event.
	//Read and Write one pair of reports.
	ReadAndWriteToDevice();

	CDialog::OnTimer(nIDEvent);
}

void CUsbhidiocDlg::OnOK() 
{
	CDialog::OnOK();
}




?? 快捷鍵說明

復制代碼 Ctrl + C
搜索代碼 Ctrl + F
全屏模式 F11
切換主題 Ctrl + Shift + D
顯示快捷鍵 ?
增大字號 Ctrl + =
減小字號 Ctrl + -
亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频
亚洲精品一区二区三区福利| 欧洲精品一区二区| 亚洲人成在线观看一区二区| 精品欧美乱码久久久久久1区2区| 欧美日本一区二区在线观看| 欧美又粗又大又爽| 欧美在线不卡视频| 欧美日韩国产美女| 日韩一区二区精品| 精品国产百合女同互慰| 久久综合一区二区| 精品久久人人做人人爽| 国产色婷婷亚洲99精品小说| 国产精品网站导航| 国产精品久久久久久一区二区三区 | 欧美日本高清视频在线观看| 欧美视频一二三区| 欧美一级免费观看| 久久久精品人体av艺术| 亚洲国产精品t66y| 国产精品嫩草影院com| 中文字幕五月欧美| 一区二区三区日韩欧美| 亚洲午夜三级在线| 免费av网站大全久久| 激情六月婷婷综合| 91色在线porny| 精品视频免费看| 亚洲精品一区二区三区蜜桃下载| 国产亚洲精品aa| 亚洲女厕所小便bbb| 三级精品在线观看| 国产成人av一区二区| 一本大道av伊人久久综合| 欧美麻豆精品久久久久久| wwwwxxxxx欧美| 亚洲美女在线国产| 麻豆91精品91久久久的内涵| 成人av网站在线观看| 欧美系列一区二区| 久久蜜桃一区二区| 亚洲3atv精品一区二区三区| 国产中文一区二区三区| 在线观看视频一区二区| 久久久久久久久岛国免费| 亚洲综合网站在线观看| 国产精品白丝jk白祙喷水网站| 一本大道久久a久久精二百| 欧美大胆人体bbbb| 亚洲黄色小说网站| 精品午夜久久福利影院| 欧美日韩精品二区第二页| 欧美国产丝袜视频| 麻豆传媒一区二区三区| 色综合久久综合网97色综合| 精品国产精品一区二区夜夜嗨| 亚洲国产精品久久不卡毛片 | 日韩精品一卡二卡三卡四卡无卡| 高清日韩电视剧大全免费| 欧美久久高跟鞋激| 综合欧美一区二区三区| 国产宾馆实践打屁股91| 日韩亚洲国产中文字幕欧美| 一区二区免费视频| 成人深夜福利app| 国产网站一区二区| 免费人成网站在线观看欧美高清| 在线免费视频一区二区| 国产精品视频看| 成人国产精品免费观看| 精品少妇一区二区三区视频免付费| 一区二区三区在线播放| 91色视频在线| 亚洲一区二区三区视频在线 | 久久―日本道色综合久久| 日韩国产在线观看| 欧美日韩国产经典色站一区二区三区| 亚洲色图欧美在线| 9人人澡人人爽人人精品| 国产精品色一区二区三区| 国产成人亚洲综合a∨猫咪| 欧美变态tickling挠脚心| 捆绑紧缚一区二区三区视频| 欧美一级在线观看| 美日韩一级片在线观看| 精品美女在线播放| 国产美女av一区二区三区| 国产色一区二区| av一二三不卡影片| 一区二区三区在线观看欧美| 欧美视频完全免费看| 亚洲成a人片综合在线| 678五月天丁香亚洲综合网| 免费欧美在线视频| 精品av综合导航| 99久久精品情趣| 亚洲最大的成人av| 91精品国产综合久久久久久漫画| 婷婷一区二区三区| 2023国产精品自拍| 成人午夜免费av| 亚洲一区二区三区精品在线| 在线电影欧美成精品| 久久成人免费电影| 国产精品久久久久一区 | 久久国产福利国产秒拍| 国产日韩欧美综合在线| 97精品视频在线观看自产线路二| 亚洲成人动漫av| 久久久91精品国产一区二区精品| 91免费在线播放| 免费的国产精品| 亚洲欧美欧美一区二区三区| 欧美精品三级日韩久久| 福利一区在线观看| 亚洲123区在线观看| 久久久精品国产免大香伊| 欧美色男人天堂| 成人高清av在线| 日韩**一区毛片| 亚洲四区在线观看| 日韩三级免费观看| 一本色道久久综合狠狠躁的推荐| 蜜臀av性久久久久av蜜臀妖精| 中文字幕不卡三区| 91精品国产综合久久久久久久 | 日韩欧美黄色影院| 色爱区综合激月婷婷| 狠狠色狠狠色综合日日91app| 亚洲免费在线视频一区 二区| 欧美电影免费观看高清完整版在线| 91小视频在线| 国产一区二区三区日韩| 亚洲成人精品影院| 亚洲三级视频在线观看| 久久精品一二三| 欧美www视频| 欧美日韩精品免费观看视频 | 亚洲另类春色国产| 久久精品欧美一区二区三区麻豆| 欧美精品视频www在线观看| 日本精品视频一区二区| 成人激情小说乱人伦| 国内精品久久久久影院薰衣草 | 性久久久久久久| 亚洲欧洲制服丝袜| 中文字幕免费观看一区| 久久久久久久免费视频了| 精品人伦一区二区色婷婷| 欧美精品自拍偷拍| 欧美日韩情趣电影| 欧美午夜一区二区三区免费大片| 色哟哟国产精品| 91啪亚洲精品| 91福利在线观看| 欧美色偷偷大香| 欧美另类videos死尸| 欧美精品日韩精品| 欧美精品在欧美一区二区少妇| 欧美日韩国产系列| 4438x成人网最大色成网站| 欧美精品一级二级三级| 91精品国产综合久久香蕉的特点| 欧美高清hd18日本| 欧美一区二区精美| 精品久久人人做人人爰| xnxx国产精品| 欧美国产一区二区| 亚洲天堂a在线| 午夜精品一区在线观看| 免费高清在线一区| 国产精品白丝jk白祙喷水网站| 成人h版在线观看| 欧美亚洲尤物久久| 欧美日韩精品综合在线| 精品人在线二区三区| 国产精品每日更新| 亚洲成人在线免费| 国产精品一二三在| 一本大道久久a久久综合| 8x福利精品第一导航| 久久久久久久综合狠狠综合| 亚洲人成精品久久久久久| 丝袜诱惑制服诱惑色一区在线观看| 日本不卡中文字幕| 福利一区二区在线观看| 欧美日韩精品一区二区三区蜜桃| 日韩欧美在线影院| 中文字幕在线不卡| 日韩av电影免费观看高清完整版 | 一区二区三区在线影院| 亚瑟在线精品视频| 国产一区二区视频在线播放| 99久久夜色精品国产网站| 欧美日韩国产综合草草| 国产亚洲精久久久久久| 午夜视频一区在线观看| 国产999精品久久久久久| 欧美午夜视频网站| 欧美国产日韩一二三区|