• R/O
  • SSH
  • HTTPS

ttssh2: Commit


Commit MetaInfo

Revision10538 (tree)
Zeit2023-01-25 23:51:13
Autorzmatsuo

Log Message

RegisterDeviceNotification() を comap_win.c に追加

- RegisterDeviceNotification()
- UnregisterDeviceNotification()

Ändern Zusammenfassung

Diff

--- trunk/teraterm/common/compat_win.cpp (revision 10537)
+++ trunk/teraterm/common/compat_win.cpp (revision 10538)
@@ -56,6 +56,8 @@
5656
5757 // user32
5858 int (WINAPI *pGetSystemMetricsForDpi)(int nIndex, UINT dpi);
59+HDEVNOTIFY (WINAPI *pRegisterDeviceNotificationA)(HANDLE hRecipient, LPVOID NotificationFilter, DWORD Flags);
60+BOOL (WINAPI *pUnregisterDeviceNotification)(HDEVNOTIFY Handle);
5961
6062 // kernel32
6163 void (WINAPI *pOutputDebugStringW)(LPCWSTR lpOutputString);
@@ -176,6 +178,8 @@
176178 { "MonitorFromRect", (void **)&pMonitorFromRect },
177179 { "GetMonitorInfoA", (void **)&pGetMonitorInfoA },
178180 { "GetSystemMetricsForDpi", (void **)&pGetSystemMetricsForDpi },
181+ { "RegisterDeviceNotificationA", (void **)&pRegisterDeviceNotificationA },
182+ { "UnregisterDeviceNotification", (void **)&pUnregisterDeviceNotification },
179183 {},
180184 };
181185
--- trunk/teraterm/common/compat_win.h (revision 10537)
+++ trunk/teraterm/common/compat_win.h (revision 10538)
@@ -158,7 +158,11 @@
158158 extern LONG_PTR (WINAPI *pSetWindowLongPtrW)(HWND hWnd, int nIndex, LONG_PTR dwNewLong);
159159 extern LONG_PTR (WINAPI *pGetWindowLongPtrW)(HWND hWnd, int nIndex);
160160 #endif
161+
162+// user32
161163 extern int (WINAPI *pGetSystemMetricsForDpi)(int nIndex, UINT dpi);
164+extern HDEVNOTIFY (WINAPI *pRegisterDeviceNotificationA)(HANDLE hRecipient, LPVOID NotificationFilter, DWORD Flags);
165+extern BOOL (WINAPI *pUnregisterDeviceNotification)(HDEVNOTIFY Handle);
162166
163167 // kernel32
164168 extern void (WINAPI *pOutputDebugStringW)(LPCWSTR lpOutputString);
--- trunk/teraterm/teraterm/vtwin.cpp (revision 10537)
+++ trunk/teraterm/teraterm/vtwin.cpp (revision 10538)
@@ -204,16 +204,13 @@
204204 Alpha = alpha;
205205 }
206206
207-void RegDeviceNotify(HWND hWnd)
207+static HDEVNOTIFY RegDeviceNotify(HWND hWnd)
208208 {
209- typedef HDEVNOTIFY (WINAPI *PRegisterDeviceNotification)(HANDLE hRecipient, LPVOID NotificationFilter, DWORD Flags);
210- HMODULE h;
211- PRegisterDeviceNotification pRegisterDeviceNotification;
212209 DEV_BROADCAST_DEVICEINTERFACE filter;
210+ HDEVNOTIFY h;
213211
214- if (((h = GetModuleHandle("user32.dll")) == NULL) ||
215- ((pRegisterDeviceNotification = (PRegisterDeviceNotification)GetProcAddress(h, "RegisterDeviceNotificationA")) == NULL)) {
216- return;
212+ if (pRegisterDeviceNotificationA == NULL) {
213+ return NULL;
217214 }
218215
219216 ZeroMemory(&filter, sizeof(filter));
@@ -220,23 +217,10 @@
220217 filter.dbcc_size = sizeof(filter);
221218 filter.dbcc_devicetype = DBT_DEVTYP_DEVICEINTERFACE;
222219 filter.dbcc_classguid = GUID_DEVINTERFACE_USB_DEVICE;
223- hDevNotify = pRegisterDeviceNotification(hWnd, &filter, DEVICE_NOTIFY_WINDOW_HANDLE);
220+ h = pRegisterDeviceNotificationA(hWnd, &filter, DEVICE_NOTIFY_WINDOW_HANDLE);
221+ return h;
224222 }
225223
226-void UnRegDeviceNotify(HWND hWnd)
227-{
228- typedef BOOL (WINAPI *PUnregisterDeviceNotification)(HDEVNOTIFY Handle);
229- HMODULE h;
230- PUnregisterDeviceNotification pUnregisterDeviceNotification;
231-
232- if (((h = GetModuleHandle("user32.dll")) == NULL) ||
233- ((pUnregisterDeviceNotification = (PUnregisterDeviceNotification)GetProcAddress(h, "UnregisterDeviceNotification")) == NULL)) {
234- return;
235- }
236-
237- pUnregisterDeviceNotification(hDevNotify);
238-}
239-
240224 void SetAutoConnectPort(int port)
241225 {
242226 AutoDisconnectedPort = port;
@@ -431,7 +415,7 @@
431415 }
432416
433417 // USBデバイス変化通知登録
434- RegDeviceNotify(HVTWin);
418+ hDevNotify = RegDeviceNotify(HVTWin);
435419
436420 // 通知領域初期化
437421 NotifyIcon *ni = Notify2Initialize();
@@ -1450,7 +1434,10 @@
14501434 UnregWin(HVTWin);
14511435
14521436 // USBデバイス変化通知解除
1453- UnRegDeviceNotify(HVTWin);
1437+ if (hDevNotify != NULL && pUnregisterDeviceNotification != NULL) {
1438+ pUnregisterDeviceNotification(hDevNotify);
1439+ hDevNotify = NULL;
1440+ }
14541441
14551442 EndKeyboard();
14561443
Show on old repository browser