From 74e209f6c8ad2f0141a252fb91d53eaa1400a27c Mon Sep 17 00:00:00 2001 From: Vadim Rozenfeld Date: Tue, 16 Jan 2024 22:25:31 +1100 Subject: [PATCH] [balloon] clean up pre-Win10 code (usermode part). Signed-off-by: Vadim Rozenfeld --- Balloon/app/blnsvr.vcxproj | 12 ++--- Balloon/app/device.cpp | 92 +------------------------------------- Balloon/app/service.cpp | 43 +++--------------- Balloon/app/service.h | 16 ++----- Balloon/app/stdafx.h | 4 -- 5 files changed, 17 insertions(+), 150 deletions(-) diff --git a/Balloon/app/blnsvr.vcxproj b/Balloon/app/blnsvr.vcxproj index 2d9c9807..e7102192 100644 --- a/Balloon/app/blnsvr.vcxproj +++ b/Balloon/app/blnsvr.vcxproj @@ -152,7 +152,7 @@ MaxSpeed true true - WIN32;NDEBUG;_CONSOLE;UNIVERSAL;%(PreprocessorDefinitions) + WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions) true ..\sys\ MultiThreaded @@ -173,7 +173,7 @@ MaxSpeed true true - WIN32;NDEBUG;_CONSOLE;UNIVERSAL;%(PreprocessorDefinitions) + WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions) true ..\sys\ MultiThreaded @@ -194,7 +194,7 @@ MaxSpeed true true - NDEBUG;_CONSOLE;UNIVERSAL;%(PreprocessorDefinitions) + NDEBUG;_CONSOLE;%(PreprocessorDefinitions) true ..\sys\ MultiThreaded @@ -215,7 +215,7 @@ MaxSpeed true true - NDEBUG;_CONSOLE;UNIVERSAL;%(PreprocessorDefinitions) + NDEBUG;_CONSOLE;%(PreprocessorDefinitions) true ..\sys\ MultiThreaded @@ -236,7 +236,7 @@ MaxSpeed true true - NDEBUG;_CONSOLE;UNIVERSAL;%(PreprocessorDefinitions) + NDEBUG;_CONSOLE;%(PreprocessorDefinitions) true ..\sys\ MultiThreaded @@ -257,7 +257,7 @@ MaxSpeed true true - NDEBUG;_CONSOLE;UNIVERSAL;%(PreprocessorDefinitions) + NDEBUG;_CONSOLE;%(PreprocessorDefinitions) true ..\sys\ MultiThreaded diff --git a/Balloon/app/device.cpp b/Balloon/app/device.cpp index 1e1b677d..644300d5 100644 --- a/Balloon/app/device.cpp +++ b/Balloon/app/device.cpp @@ -69,7 +69,7 @@ VOID CDevice::Fini() DWORD CDevice::Run() { - PWCHAR DevicePath = GetDevicePath((LPGUID)&GUID_DEVINTERFACE_BALLOON); + PWCHAR DevicePath = GetDevicePath((LPGUID)&GUID_DEVINTERFACE_BALLOON); if (DevicePath == NULL) { PrintMessage("File not found."); return ERROR_FILE_NOT_FOUND; @@ -85,7 +85,7 @@ DWORD CDevice::Run() return GetLastError(); } - NOTIFY_HANDLE devnotify = m_pService->RegisterDeviceHandleNotification( + HCMNOTIFICATION devnotify = m_pService->RegisterDeviceHandleNotification( hDevice); if (!devnotify) { @@ -192,92 +192,6 @@ DWORD WINAPI CDevice::DeviceThread(LPDWORD lParam) return pDev->Run(); } -#ifndef UNIVERSAL - -PTCHAR CDevice::GetDevicePath( IN LPGUID InterfaceGuid ) -{ - HDEVINFO HardwareDeviceInfo; - SP_DEVICE_INTERFACE_DATA DeviceInterfaceData; - PSP_DEVICE_INTERFACE_DETAIL_DATA DeviceInterfaceDetailData = NULL; - ULONG Length, RequiredLength = 0; - BOOL bResult; - PTCHAR DevicePath; - - HardwareDeviceInfo = SetupDiGetClassDevs( - InterfaceGuid, - NULL, - NULL, - (DIGCF_PRESENT | DIGCF_DEVICEINTERFACE) - ); - - if (HardwareDeviceInfo == INVALID_HANDLE_VALUE) { - PrintMessage("Cannot get class devices"); - return NULL; - } - - DeviceInterfaceData.cbSize = sizeof(SP_DEVICE_INTERFACE_DATA); - - bResult = SetupDiEnumDeviceInterfaces( - HardwareDeviceInfo, - 0, - InterfaceGuid, - 0, - &DeviceInterfaceData - ); - - if (bResult == FALSE) { - PrintMessage("Cannot get enumerate device interfaces"); - SetupDiDestroyDeviceInfoList(HardwareDeviceInfo); - return NULL; - } - - SetupDiGetDeviceInterfaceDetail( - HardwareDeviceInfo, - &DeviceInterfaceData, - NULL, - 0, - &RequiredLength, - NULL - ); - - DeviceInterfaceDetailData = (PSP_DEVICE_INTERFACE_DETAIL_DATA) LocalAlloc(LMEM_FIXED, RequiredLength); - - if (DeviceInterfaceDetailData == NULL) { - PrintMessage("Cannot allocate memory"); - SetupDiDestroyDeviceInfoList(HardwareDeviceInfo); - return NULL; - } - - DeviceInterfaceDetailData->cbSize = sizeof(SP_DEVICE_INTERFACE_DETAIL_DATA); - - Length = RequiredLength; - - bResult = SetupDiGetDeviceInterfaceDetail( - HardwareDeviceInfo, - &DeviceInterfaceData, - DeviceInterfaceDetailData, - Length, - &RequiredLength, - NULL - ); - - if (bResult == FALSE) { - PrintMessage("Cannot get device interface details"); - SetupDiDestroyDeviceInfoList(HardwareDeviceInfo); - LocalFree(DeviceInterfaceDetailData); - return NULL; - } - - DevicePath = _tcsdup(DeviceInterfaceDetailData->DevicePath); - - SetupDiDestroyDeviceInfoList(HardwareDeviceInfo); - LocalFree(DeviceInterfaceDetailData); - - return DevicePath; -} - -#else // UNIVERSAL - PTCHAR CDevice::GetDevicePath(IN LPGUID InterfaceGuid) { PWSTR DeviceInterfaceList = NULL; @@ -327,5 +241,3 @@ PTCHAR CDevice::GetDevicePath(IN LPGUID InterfaceGuid) return DevicePath; } - -#endif // UNIVERSAL diff --git a/Balloon/app/service.cpp b/Balloon/app/service.cpp index 09a83a74..84620cfa 100644 --- a/Balloon/app/service.cpp +++ b/Balloon/app/service.cpp @@ -248,8 +248,6 @@ void CService::GetStatus(SC_HANDLE service) SendStatusToSCM(CurrentState, NO_ERROR, 0, 0, 0); } -#ifdef UNIVERSAL - DWORD WINAPI CService::DeviceNotificationCallback(HCMNOTIFICATION Notify, PVOID Context, CM_NOTIFY_ACTION Action, PCM_NOTIFY_EVENT_DATA EventData, DWORD EventDataSize) @@ -296,13 +294,10 @@ VOID WINAPI UnregisterNotificationWork(PTP_CALLBACK_INSTANCE Instance, CloseThreadpoolWork(Work); } -#endif // UNIVERSAL - -NOTIFY_HANDLE CService::RegisterDeviceInterfaceNotification() +HCMNOTIFICATION CService::RegisterDeviceInterfaceNotification() { - NOTIFY_HANDLE handle = NULL; + HCMNOTIFICATION handle = NULL; -#ifdef UNIVERSAL CM_NOTIFY_FILTER filter; CONFIGRET cr; @@ -319,26 +314,13 @@ NOTIFY_HANDLE CService::RegisterDeviceInterfaceNotification() SetLastError(CM_MapCrToWin32Err(cr, ERROR_NOT_SUPPORTED)); } -#else // UNIVERSAL - DEV_BROADCAST_DEVICEINTERFACE filter; - - ZeroMemory(&filter, sizeof(filter)); - filter.dbcc_size = sizeof(filter); - filter.dbcc_devicetype = DBT_DEVTYP_DEVICEINTERFACE; - filter.dbcc_classguid = GUID_DEVINTERFACE_BALLOON; - - handle = ::RegisterDeviceNotification(m_StatusHandle, &filter, - DEVICE_NOTIFY_SERVICE_HANDLE); -#endif // UNIVERSAL - return handle; } -NOTIFY_HANDLE CService::RegisterDeviceHandleNotification(HANDLE DeviceHandle) +HCMNOTIFICATION CService::RegisterDeviceHandleNotification(HANDLE DeviceHandle) { - NOTIFY_HANDLE handle = NULL; + HCMNOTIFICATION handle = NULL; -#ifdef UNIVERSAL CM_NOTIFY_FILTER filter; CONFIGRET cr; @@ -354,28 +336,16 @@ NOTIFY_HANDLE CService::RegisterDeviceHandleNotification(HANDLE DeviceHandle) { SetLastError(CM_MapCrToWin32Err(cr, ERROR_NOT_SUPPORTED)); } -#else // UNIVERSAL - DEV_BROADCAST_HANDLE filter; - - ZeroMemory(&filter, sizeof(filter)); - filter.dbch_size = sizeof(filter); - filter.dbch_devicetype = DBT_DEVTYP_HANDLE; - filter.dbch_handle = DeviceHandle; - - handle = ::RegisterDeviceNotification(m_StatusHandle, &filter, - DEVICE_NOTIFY_SERVICE_HANDLE); -#endif // UNIVERSAL return handle; } -BOOL CService::UnregisterNotification(NOTIFY_HANDLE Handle) +BOOL CService::UnregisterNotification(HCMNOTIFICATION Handle) { BOOL ret = FALSE; if (Handle) { -#ifdef UNIVERSAL PTP_WORK work; work = CreateThreadpoolWork(UnregisterNotificationWork, Handle, NULL); @@ -385,9 +355,6 @@ BOOL CService::UnregisterNotification(NOTIFY_HANDLE Handle) } ret = TRUE; -#else // UNIVERSAL - ret = ::UnregisterDeviceNotification(Handle); -#endif // UNIVERSAL } return ret; diff --git a/Balloon/app/service.h b/Balloon/app/service.h index 9a27a616..528f2799 100644 --- a/Balloon/app/service.h +++ b/Balloon/app/service.h @@ -4,12 +4,6 @@ #include #include -#ifdef UNIVERSAL -#define NOTIFY_HANDLE HCMNOTIFICATION -#else -#define NOTIFY_HANDLE HDEVNOTIFY -#endif - class CDevice; class CService @@ -23,15 +17,13 @@ public: static void __stdcall ServiceMainThunk(CService* service, DWORD argc, TCHAR* argv[]); SERVICE_STATUS_HANDLE m_StatusHandle; - NOTIFY_HANDLE RegisterDeviceInterfaceNotification(); - NOTIFY_HANDLE RegisterDeviceHandleNotification(HANDLE DeviceHandle); - BOOL UnregisterNotification(NOTIFY_HANDLE Handle); + HCMNOTIFICATION RegisterDeviceInterfaceNotification(); + HCMNOTIFICATION RegisterDeviceHandleNotification(HANDLE DeviceHandle); + BOOL UnregisterNotification(HCMNOTIFICATION Handle); -#ifdef UNIVERSAL static DWORD WINAPI DeviceNotificationCallback(HCMNOTIFICATION Notify, PVOID Context, CM_NOTIFY_ACTION Action, PCM_NOTIFY_EVENT_DATA EventData, DWORD EventDataSize); -#endif private: BOOL SendStatusToSCM(DWORD dwCurrentState, DWORD dwWin32ExitCode, DWORD dwServiceSpecificExitCode, DWORD dwCheckPoint, DWORD dwWaitHint); @@ -42,7 +34,7 @@ private: DWORD ServiceHandleDeviceChange(DWORD evtype); DWORD ServiceHandlePowerEvent(DWORD evtype, DWORD flags); - NOTIFY_HANDLE m_hDevNotify; + HCMNOTIFICATION m_hDevNotify; HANDLE m_evTerminate; BOOL m_bRunningService; DWORD m_Status; diff --git a/Balloon/app/stdafx.h b/Balloon/app/stdafx.h index 92808630..e120e894 100644 --- a/Balloon/app/stdafx.h +++ b/Balloon/app/stdafx.h @@ -13,11 +13,7 @@ #include #include #include - -#ifdef UNIVERSAL #include -#endif // UNIVERSAL - #include "targetver.h" #include "utils.h" #include "service.h"