全國最多中醫師線上諮詢網站-台灣中醫網
發文 回覆 瀏覽次數:2370
推到 Plurk!
推到 Facebook!

Header Definition: UsbHidApi.h

 
jackkcg
站務副站長


發表:891
回覆:1050
積分:848
註冊:2002-03-23

發送簡訊給我
#1 引用回覆 回覆 發表時間:2003-10-26 01:55:14 IP:61.64.xxx.xxx 未訂閱
http://www.kadtronix.com/usbhidapi_hdr.htm http://www.kadtronix.com/usbhidapi.htm Header Definition: UsbHidApi.h /*******************************************************************/ /* /* File Name: UsbHidApi.h /* /* Copyright 2003, All rights reserved. /* /* Description: /* /* This DLL provides a relatively simple method for accessing /* a USB HID device [Open(), Read(), Write()]. (The device must /* use HID reports.) /* /* Client applications use the exported methods from the /* CUsbHidApi class to identify and access external /* HID device(s). A new instance of the class must /* be created for each device being accessed. /* /* /* /* Revision History: /* /* Name Date Description /* ---- ---- ----------- /* K.Delahoussaye 5/13/03 Initial version /* /*******************************************************************/ // // Notes: // ----- // // This DLL provides the client application an easy method for accessing // an HID device via USB link. The acts of reading and writing // a USB device under Windows are significantly different and more // involved than for other comm devices such as serial comm ports. // For this reason, it seemed necessary to encapsulate the complexity // of the interface within a DLL. This DLL provides all the required // functions for accessing the device, while hiding the details // of the implementation. // // The USB link is implemented as a Human Interface Device (HID) class // function. As such, the DLL is dependent on the following Windows // drivers: // // hidclass.sys hidparse.sys hidusb.sys // // In addition to being USB-compliant, the host PC should have the // latest, versions of these drivers. (Initial development was done // using drivers from Windows 98, 2nd edition and Windows 2000.) // // The module was built using Microsoft Visual C , 6.0 as a Win32, // non-MFC DLL. Since there is no dependence on the Microsoft // Foundation Class (MFC), there is no need to copy additional MFC // DLLs to your Windows system folder. Also, no dependence on MFC // means the size of the DLL itself is minimal. (Although the DLL // does not internally use the MFC, the client application is not // restricted. Exported functions in the DLL may be called by either // MFC or non-MFC applications.) // // The client application may link implicitly or explicitly with the // DLL. In explicit linking, the client application makes function // calls to explicitly load and unload the DLL's exported functions. // In implicit linking, the application links to an import library // (UsbHidApi.lib) and makes function calls just as if the functions // were contained within the executable. // #define USBHIDAPI_DLL_NAME "UsbHidApi.dll" // The following ifdef block is the standard way of creating macros which make exporting // from a DLL simpler. All files within this DLL are compiled with the USBHIDAPI_EXPORTS // symbol defined on the command line. this symbol should not be defined on any project // that uses this DLL. This way any other project whose source files include this file see // USBHIDAPI_API functions as being imported from a DLL, whereas this DLL sees symbols // defined with this macro as being exported. #ifdef USBHIDAPI_EXPORTS #define USBHIDAPI_API __declspec(dllexport) #else #define USBHIDAPI_API __declspec(dllimport) #endif // This structure defines an entry in a device list // The list describes the parameters associated with // a device. It is mainly used with the GetList() // function. typedef struct { char DeviceName[50]; // Device name char Manufacturer[50]; // Manufacturer char SerialNumber[20]; // Serial number unsigned int VendorID; // Vendor ID unsigned int ProductID; // Product ID int InputReportLen; // Length of HID input report (bytes) int OutputReportLen; // Length of HID output report (bytes) } mdeviceList; // This class is exported from the UsbHidApi.dll class USBHIDAPI_API CUsbHidApi { public: // The serial number for the open device char m_SerialNumber[20]; // These variables define the required lengths for reading and writing // the device. unsigned short m_ReadSize; unsigned short m_WriteSize; // Constructor CUsbHidApi(void); // Destructor ~CUsbHidApi(void); // Get list of devices and their availability. Caller must supply a // pointer to a buffer that will hold the list of structure entries. // Must also supply an integer representing maximum no. of entries // his buffer can hold. Returns total number stored. int GetList(unsigned int VendorID, // Vendor ID to search (0xffff if unused) unsigned int ProductID, // Product ID to search (0xffff if unused) char *Manufacturer, // Manufacturer (NULL if unused) char *SerialNum, // Serial number to search (NULL if unused) char *DeviceName, // Device name to search (NULL if unused) mdeviceList *pList, // Caller's array for storing matching device(s) int nMaxDevices); // Size of the caller's array list (no.entries) // Open a USB comm link to a HID device. Returns non-zero // on success or 0 on failure. (Individual read and write handles // are maintained internally.) If the caller desires to open // a specific HID device, he must provide one or more // specifiers (i.e., vendor ID, product ID, serial number, // or device name. If a successful open occurs, the function // returns TRUE. It returns FALSE otherwise. int Open (unsigned int VendorID, // Vendor ID to search (0xffff if unused) unsigned int ProductID, // Product ID to search (0xffff if unused) char *Manufacturer, // Manufacturer (NULL if unused) char *SerialNum, // Serial number to search (0xffff if unused) char *DeviceName, // Device name to search (NULL if unused) int bAsync); // Set TRUE for non-blocking read requests. // Close the read pipe void CloseRead(void); // Close the write pipe void CloseWrite(void); // Read a report from the HID device. The number of bytes read is // determined by the input report length specified by the device. // Depending on how the device was opened, the call may perform // blocking or non-blocking reads. Refer to Open() for details. // On success, the call returns the number of bytes actually read. // A negative return value indicates an error (most likely means // the USB cable has been disconnected or device was powered off). // (Note: The first byte location is usually a report ID // [typically = 0]. The caller must account for this value in // the read buffer.) int Read(void *pBuf); // Buffer for storing bytes // Write a report to the HID device. The number of bytes to // write depend on the output report length specified by the // device. Returns number of bytes actually written. A negative // return value indicates an error (most likely means the // USB cable has been disconnected or device was powered off). // (Note: The first byte location is usually a report ID // [typically = 0]. The caller must ensure this value is // prepended to the buffer.) int Write(void *pBuf); // Buffer containing bytes to write // This function retrieves the lengths of input- and output-reports // for the device. These values determine the I/O lengths for the // Read() and Write() functions. The device must be opened prior // to calling this routine. Alternatively, you can just use m_ReadSize // and m_WriteSize. void GetReportLengths (int *input_len, // Pointer for storing input length int *output_len); // Pointer for storing output length // Private (internal) declarations private: // This function reads an input report from an open device. // The call will block until any number of bytes is retrieved, // up to the maximum of nBytesToRead. On successful completion, // the function returns an integer representing the // number of bytes read (usually the input report length // defined by the device). (Note: The read buffer must // be large enough to accommodate the report length. This // number is located in m_ReadSize.) int ReadSync(void *pBuf); // Buffer for storing bytes // Read input report from an open device. If no data // is currently available, the call will not block, // but will return 0. On successful completion, // the function returns an integer representing the // number of bytes read (usually the input report length // defined by the device). The function returns -2 if // disconnect is detected. (Note: The read buffer must // be large enough to accommodate the report length. This // number is located in m_ReadSize.) int ReadAsync(void *pBuf); // Buffer for storing bytes // Read/write handles. While a single handle could suffice for // both operations, 2 handles have been created to allow the client // application to utilize separate threads for reading and writing. HANDLE ReadHandle; HANDLE WriteHandle; }; ********************************************************* 哈哈&兵燹 最會的2大絕招 這個不會與那個也不會 哈哈哈 粉好 Delphi K.Top的K.Top分兩個字解釋Top代表尖端的意思,希望本討論區能提供Delphi的尖端新知 K.表Knowlege 知識,就是本站的標語:Open our mind to make knowledge together! 希望能大家敞開心胸,將知識寶庫結合一起
------
**********************************************************
哈哈&兵燹
最會的2大絕招 這個不會與那個也不會 哈哈哈 粉好

Delphi K.Top的K.Top分兩個字解釋Top代表尖端的意思,希望本討論區能提供Delphi的尖端新知
K.表Knowlege 知識,就是本站的標語:Open our mind
系統時間:2024-03-29 5:30:39
聯絡我們 | Delphi K.Top討論版
本站聲明
1. 本論壇為無營利行為之開放平台,所有文章都是由網友自行張貼,如牽涉到法律糾紛一切與本站無關。
2. 假如網友發表之內容涉及侵權,而損及您的利益,請立即通知版主刪除。
3. 請勿批評中華民國元首及政府或批評各政黨,是藍是綠本站無權干涉,但這裡不是政治性論壇!