如何编写Windows CE.net的usb驱动程序(2)
szDriverLibFile,
gcszMouseDriverId,NULL,DriverSettings);
if(!fRet)
{
//BUGBUGunregistertheClientDriver’sID
}
}
}
else
{
RETAILMSG(1,(TEXT(!USBMouse:ErrorgettingUSBDfunctionpointersrn)));
}
FreeLibrary(hInst);
}
returnfRet;
}
上述代码主要用于产生USB设备驱动程序需要的注册表信息,需要注意的是:USB设备驱动程序不使用标准的注册表函数,而是使用RegisterClientDriverID()和RegisterClientSettings来注册相应的设备信息。
另外一个函数是USBUninstallDriver()函数,具体代码如下:
externCBOOL
USBUnInstallDriver()
{
BOOLfRet=FALSE;
HINSTANCEhInst=LoadLibrary(LUSBD.DLL);
if(hInst)
{
LPUN_REGISTER_CLIENT_DRIVER_IDpUnRegisterId=
(LPUN_REGISTER_CLIENT_DRIVER_ID)
GetProcAddress(hInst,gcszUnRegisterClientDriverId);
LPUN_REGISTER_CLIENT_SETTINGSpUnRegisterSettings=
(LPUN_REGISTER_CLIENT_SETTINGS)GetProcAddress(hInst,
gcszUnRegisterClientSettings);
if(pUnRegisterSettings)
{
USB_DRIVER_SETTINGSDriverSettings;
DriverSettings.dwCount=sizeof(DriverSettings);
//必须填入与注册时相同的信息。
DriverSettings.dwVendorId=USB_NO_INFO;
DriverSettings.dwProductId=USB_NO_INFO;
DriverSettings.dwReleaseNumber=USB_NO_INFO;
DriverSettings.dwDeviceClass=USB_NO_INFO;
DriverSettings.dwDeviceSubClass=USB_NO_INFO;
DriverSettings.dwDeviceProtocol=USB_NO_INFO;
DriverSettings.dwInterfaceClass=0x03;//HID
DriverSettings.dwInterfaceSubClass=0x01;//bootdevice
DriverSettings.dwInterfaceProtocol=0x02;//mouse
fRet=(*pUnRegisterSettings)(gcszMouseDriverId,NULL,
DriverSettings);
}
if(pUnRegisterId)
{
BOOLfRetTemp=(*pUnRegisterId)(gcszMouseDriverId);
fRet=fRet?fRetTemp:fRet;
}
FreeLibrary(hInst);
}
returnfRet;
}
此函数主要用于删除USBInstallDriver()时创建的注册表信息,同样的它使用自己的函数接口UnRegisterClientDriverID()和UnRegisterClientSettings()来做相应的处理。
另外一个需要处理的注册的监控通知函数USBDeviceNotifications():
externCBOOLUSBDeviceNotifications(LPVOIDlpvNotifyParameter,DWORDdwCode,
LPDWORD*dwInfo1,LPDWORD*dwInfo2,LPDWORD*dwInfo3,
LPDWORD*dwInfo4)
{
CMouse*pMouse=(CMouse*)lpvNotifyParameter;
switch(dwCode)
{
caseUSB_CLOSE_DEVICE:
//删除相关的资源。
deletepMouse;
returnTRUE;
}
returnFALSE;
}
USB鼠标的类的定义如下:
classCMouse
{
public:
CMouse::CMouse(USB_HANDLEhDevice,LPCUSB_FUNCSlpUsbFuncs,
LPCUSB_INTERFACElpInterface);
~CMouse();
BOOLInitialize();
private:
//传输完毕调用的回调函数
staticDWORDCALLBACKMouseTransferCompleteStub(LPVOIDlpvNotifyParameter);
//中断处理函数
staticULONGCALLBACKCMouse::MouseThreadStub(PVOIDcontext);
DWORDMouseTransferComplete();
DWORDMouseThread();
BOOLSubmitInterrupt();
BOOLHandleInterrupt();
BOOLm_fClosing;
BOOLm_fReadyForMouseEvents;
HANDLEm_hEvent;
HANDLEm_hThread;
USB_HANDLEm_hDevice;
USB_PIPEm_hInterruptPipe;
USB_TRANSFERm_hInterruptTransfer;
LPCUSB_FUNCSm_lpUsbFuncs;
LPCUSB_INTERFACEm_pInterface;
BOOLm_fPrevButton1;
BOOLm_fPrevButton2;
BOOLm_fPrevButton3;
//数据接受缓冲区。
BYTEm_pbDataBuffer[8];
};
具体实现如下:
//构造函数,初始化时调用
CMouse::CMouse(USB_HANDLEhDevice,LPCUSB_FUNCSlpUsbFuncs,
LPCUSB_INTERFACElpInterface)
{
m_fClosing=FALSE;
m_fReadyForMouseEvents=FALSE;
m_hEvent=NULL;
m_hThread=NULL;
m_hDevice=hDevice;
m_hInterruptPipe=NULL;
m_hInterruptTransfer=NULL;
m_lpUsbFuncs=lpUsbFuncs;
m_pInterface=lpInterface;
m_fPrevButton1=FALSE;
m_fPrevButton2=FALSE;
m_fPrevButton3=FALSE;
memset(m_pbDataBuffer,0,sizeof(m_pbDataBuffer));
}
//析构函数,用于清除申请的资源。
CMouse::~CMouse()
{
//通知系统去关闭相关的函数接口。
m_fClosing=TRUE;
//Wakeuptheconnectionthreadagainandgiveittimetodie.
if(m_hEvent!=NULL)
{
//通知关闭数据接受线程。
SetEvent(m_hEvent);
if(m_hThread!=NULL)
{
DWORDdwWaitReturn;
dwWaitReturn=WaitForSingleObject(m_hThread,1000);
if(dwWaitReturn!=WAIT_OBJECT_0)
{
TerminateThread(m_hThread,DWORD(-1));
}
CloseHandle(m_hThread);
m_hThread=NULL;
}
CloseHandle(m_hEvent);
m_hEven
usb 驱动程序 CE net Windows 编写 如何 相关文章:
- Linux系统下USB摄像头驱动程序开发(04-25)
- 基于uClinux嵌入式系统的汽车黑匣子的设计(07-08)
- 基于WinCE操作系统的通用USB数控键盘设计(08-05)
- 基于WinCE的ARM视频监控系统(11-14)
- 基于LabVIEW的USB实时数据采集处理系统的实现(03-26)
- 基于DSP和USB的高速数据采集与处理系统设计(05-01)