DWORD CNdasService::OnServiceDeviceEvent(DWORD dwEventType, LPVOID lpEventData) { // // Ignore if pDeviceEventHandler is not available yet. // CNdasServiceDeviceEventHandler *pDeviceEventHandler = pGetNdasDeviceEventHandler(); if (NULL == pDeviceEventHandler) { DPWarning(_FT("NdasServicePnpHandler not yet available.\n")); return NO_ERROR; } // // Return code for services and Windows applications // for handling Device Events are different // Device Event Handler is based on Windows application, // which will return TRUE or BROADCAST_QUERY_DENY // // For services: // // If your service handles SERVICE_CONTROL_DEVICEEVENT, // return NO_ERROR to grant the request // and an error code to deny the request. // LRESULT lResult = pDeviceEventHandler->OnDeviceEvent( dwEventType, (LPARAM)lpEventData); if (BROADCAST_QUERY_DENY == lResult) { return 1; } else { return NO_ERROR; } }
BOOL CNdasLogicalDevice::ReconcileFromNdasBus() { BOOL fSuccess; HANDLE hAlarm, hDisconnect; fSuccess = ::LsBusCtlQueryPdoEvent( m_NdasScsiLocation.SlotNo, &hAlarm, &hDisconnect); // // Reconciliation failure? // if (!fSuccess) { DBGPRT_ERR_EX( _FT("LsBusCtlQueryPdoEvent at %s failed: "), m_NdasScsiLocation.ToString()); } else { fSuccess = ::CloseHandle(m_hAlarmEvent); _ASSERTE(fSuccess); m_hAlarmEvent = hAlarm; fSuccess = ::CloseHandle(m_hDisconnectedEvent); _ASSERTE(fSuccess); m_hDisconnectedEvent = hDisconnect; } PLSMPIOCTL_ADAPTERLURINFO pLurInfo = NULL; fSuccess = ::LsBusCtlQueryMiniportFullInformation( m_NdasScsiLocation.SlotNo, &pLurInfo); if (!fSuccess) { DBGPRT_ERR_EX( _FT("QueryMiniportFullInformation at %s failed: "), m_NdasScsiLocation.ToString()); } else { // pLurInfo->Adapter.Status; m_dwCurrentMRB = pLurInfo->Adapter.MaxBlocksPerRequest; SetMountedAccess(pLurInfo->Lur.DesiredAccess); } HANDLE hNdasScsi = NULL; fSuccess = ::LsBusCtlQueryPdoFileHandle( m_NdasScsiLocation.SlotNo, &hNdasScsi); AutoFileHandle autoNdasScsiHandle = hNdasScsi; if (!fSuccess || INVALID_HANDLE_VALUE == hNdasScsi) { DBGPRT_ERR_EX( _FT("QueryPdoFileHandle at %s failed: "), m_NdasScsiLocation.ToString()); } else { CNdasServiceDeviceEventHandler* pPnpHandler = pGetNdasDeviceEventHandler(); _ASSERTE(NULL != pPnpHandler); if (NULL != pPnpHandler) { fSuccess = pPnpHandler->AddDeviceNotificationHandle( m_NdasScsiLocation.SlotNo, hNdasScsi); if (!fSuccess) { DBGPRT_ERR_EX( _FT("AddDeviceNotificationHandle(%s) failed: "), m_NdasScsiLocation.ToString()); } } } SetStatus(NDAS_LOGICALDEVICE_STATUS_MOUNTED); return TRUE; }