色婷婷AⅤ一区二区三区|亚洲精品第一国产综合亚AV|久久精品官方网视频|日本28视频香蕉

          新聞中心

          EEPW首頁(yè) > 嵌入式系統(tǒng) > 設(shè)計(jì)應(yīng)用 > 如何編寫(xiě)Windows CE.net的usb驅(qū)動(dòng)程序(2)

          如何編寫(xiě)Windows CE.net的usb驅(qū)動(dòng)程序(2)

          作者: 時(shí)間:2012-05-02 來(lái)源:網(wǎng)絡(luò) 收藏

          另外一個(gè)函數(shù)是USBUninstallDriver()函數(shù),具體代碼如下:

          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);

          //必須填入與注冊(cè)時(shí)相同的信息。

          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;

          }

          此函數(shù)主要用于刪除USBInstallDriver()時(shí)創(chuàng)建的注冊(cè)表信息,同樣的它使用自己的函數(shù)接口UnRegisterClientDriverID()和UnRegisterClientSettings()來(lái)做相應(yīng)的處理。

          另外一個(gè)需要處理的注冊(cè)的監(jiān)控通知函數(shù)USBDeviceNotifications():

          externCBOOLUSBDeviceNotifications(LPVOIDlpvNotifyParameter,DWORDdwCode,

          LPDWORD*dwInfo1,LPDWORD*dwInfo2,LPDWORD*dwInfo3,

          LPDWORD*dwInfo4)

          {

          CMouse*pMouse=(CMouse*)lpvNotifyParameter;

          switch(dwCode)

          {

          caseUSB_CLOSE_DEVICE:

          //刪除相關(guān)的資源。

          deletepMouse;

          returnTRUE;

          }

          returnFALSE;

          }

          USB鼠標(biāo)的類(lèi)的定義如下:

          classCMouse

          {

          public:

          CMouse::CMouse(USB_HANDLEhDevice,LPCUSB_FUNCSlpUsbFuncs,

          LPCUSB_INTERFACElpInterface);

          ~CMouse();

          BOOLInitialize();

          private:

          //傳輸完畢調(diào)用的回調(diào)函數(shù)

          staticDWORDCALLBACKMouseTransferCompleteStub(LPVOIDlpvNotifyParameter);

          //中斷處理函數(shù)

          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;

          //數(shù)據(jù)接受緩沖區(qū)。

          BYTEm_pbDataBuffer[8];

          };

          具體實(shí)現(xiàn)如下:

          //構(gòu)造函數(shù),初始化時(shí)調(diào)用

          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));

          }

          //析構(gòu)函數(shù),用于清除申請(qǐng)的資源。

          CMouse::~CMouse()

          {

          //通知系統(tǒng)去關(guān)閉相關(guān)的函數(shù)接口。

          m_fClosing=TRUE;

          //Wakeuptheconnectionthreadagainandgiveittimetodie.

          if(m_hEvent!=NULL)

          {

          //通知關(guān)閉數(shù)據(jù)接受線程。

          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_hEvent=NULL;

          }

          if(m_hInterruptTransfer)

          (*m_lpUsbFuncs->lpCloseTransfer)(m_hInterruptTransfer);

          if(m_hInterruptPipe)

          (*m_lpUsbFuncs->lpClosePipe)(m_hInterruptPipe);

          }

          //初始化USB鼠標(biāo)

          BOOLCMouse::Initialize()

          {

          LPCUSB_DEVICElpDeviceInfo=(*m_lpUsbFuncs->lpGetDeviceInfo)(m_hDevice);

          //檢測(cè)配置:USB鼠標(biāo)應(yīng)該只有一個(gè)中斷管道

          if((m_pInterface->lpEndpoints[0].Descriptor.bmAttributesUSB_ENDPOINT_TYPE_MASK)!=USB_ENDPOINT_TYPE_INTERRUPT)

          {

          RETAILMSG(1,(TEXT(!USBMouse:EP0wrongtype(%u)!rn),



          評(píng)論


          相關(guān)推薦

          技術(shù)專區(qū)

          關(guān)閉