在线看毛片网站电影-亚洲国产欧美日韩精品一区二区三区,国产欧美乱夫不卡无乱码,国产精品欧美久久久天天影视,精品一区二区三区视频在线观看,亚洲国产精品人成乱码天天看,日韩久久久一区,91精品国产91免费

<menu id="6qfwx"><li id="6qfwx"></li></menu>
    1. <menu id="6qfwx"><dl id="6qfwx"></dl></menu>

      <label id="6qfwx"><ol id="6qfwx"></ol></label><menu id="6qfwx"></menu><object id="6qfwx"><strike id="6qfwx"><noscript id="6qfwx"></noscript></strike></object>
        1. <center id="6qfwx"><dl id="6qfwx"></dl></center>

            新聞中心

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

            如何編寫Windows CE.net的usb驅(qū)動程序(2)

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

            另外一個函數(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);

            //必須填入與注冊時相同的信息。

            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()時創(chuàng)建的注冊表信息,同樣的它使用自己的函數(shù)接口UnRegisterClientDriverID()和UnRegisterClientSettings()來做相應(yīng)的處理。

            另外一個需要處理的注冊的監(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)的類的定義如下:

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

            };

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

            //構(gòu)造函數(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ù),用于清除申請的資源。

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

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

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

            {

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



            評論


            相關(guān)推薦

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

            關(guān)閉