RegisterDeviceNotification() を comap_win.c に追加
- RegisterDeviceNotification()
- UnregisterDeviceNotification()
@@ -56,6 +56,8 @@ | ||
56 | 56 | |
57 | 57 | // user32 |
58 | 58 | int (WINAPI *pGetSystemMetricsForDpi)(int nIndex, UINT dpi); |
59 | +HDEVNOTIFY (WINAPI *pRegisterDeviceNotificationA)(HANDLE hRecipient, LPVOID NotificationFilter, DWORD Flags); | |
60 | +BOOL (WINAPI *pUnregisterDeviceNotification)(HDEVNOTIFY Handle); | |
59 | 61 | |
60 | 62 | // kernel32 |
61 | 63 | void (WINAPI *pOutputDebugStringW)(LPCWSTR lpOutputString); |
@@ -176,6 +178,8 @@ | ||
176 | 178 | { "MonitorFromRect", (void **)&pMonitorFromRect }, |
177 | 179 | { "GetMonitorInfoA", (void **)&pGetMonitorInfoA }, |
178 | 180 | { "GetSystemMetricsForDpi", (void **)&pGetSystemMetricsForDpi }, |
181 | + { "RegisterDeviceNotificationA", (void **)&pRegisterDeviceNotificationA }, | |
182 | + { "UnregisterDeviceNotification", (void **)&pUnregisterDeviceNotification }, | |
179 | 183 | {}, |
180 | 184 | }; |
181 | 185 |
@@ -158,7 +158,11 @@ | ||
158 | 158 | extern LONG_PTR (WINAPI *pSetWindowLongPtrW)(HWND hWnd, int nIndex, LONG_PTR dwNewLong); |
159 | 159 | extern LONG_PTR (WINAPI *pGetWindowLongPtrW)(HWND hWnd, int nIndex); |
160 | 160 | #endif |
161 | + | |
162 | +// user32 | |
161 | 163 | 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); | |
162 | 166 | |
163 | 167 | // kernel32 |
164 | 168 | extern void (WINAPI *pOutputDebugStringW)(LPCWSTR lpOutputString); |
@@ -204,16 +204,13 @@ | ||
204 | 204 | Alpha = alpha; |
205 | 205 | } |
206 | 206 | |
207 | -void RegDeviceNotify(HWND hWnd) | |
207 | +static HDEVNOTIFY RegDeviceNotify(HWND hWnd) | |
208 | 208 | { |
209 | - typedef HDEVNOTIFY (WINAPI *PRegisterDeviceNotification)(HANDLE hRecipient, LPVOID NotificationFilter, DWORD Flags); | |
210 | - HMODULE h; | |
211 | - PRegisterDeviceNotification pRegisterDeviceNotification; | |
212 | 209 | DEV_BROADCAST_DEVICEINTERFACE filter; |
210 | + HDEVNOTIFY h; | |
213 | 211 | |
214 | - if (((h = GetModuleHandle("user32.dll")) == NULL) || | |
215 | - ((pRegisterDeviceNotification = (PRegisterDeviceNotification)GetProcAddress(h, "RegisterDeviceNotificationA")) == NULL)) { | |
216 | - return; | |
212 | + if (pRegisterDeviceNotificationA == NULL) { | |
213 | + return NULL; | |
217 | 214 | } |
218 | 215 | |
219 | 216 | ZeroMemory(&filter, sizeof(filter)); |
@@ -220,23 +217,10 @@ | ||
220 | 217 | filter.dbcc_size = sizeof(filter); |
221 | 218 | filter.dbcc_devicetype = DBT_DEVTYP_DEVICEINTERFACE; |
222 | 219 | 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; | |
224 | 222 | } |
225 | 223 | |
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 | - | |
240 | 224 | void SetAutoConnectPort(int port) |
241 | 225 | { |
242 | 226 | AutoDisconnectedPort = port; |
@@ -431,7 +415,7 @@ | ||
431 | 415 | } |
432 | 416 | |
433 | 417 | // USBデバイス変化通知登録 |
434 | - RegDeviceNotify(HVTWin); | |
418 | + hDevNotify = RegDeviceNotify(HVTWin); | |
435 | 419 | |
436 | 420 | // 通知領域初期化 |
437 | 421 | NotifyIcon *ni = Notify2Initialize(); |
@@ -1450,7 +1434,10 @@ | ||
1450 | 1434 | UnregWin(HVTWin); |
1451 | 1435 | |
1452 | 1436 | // USBデバイス変化通知解除 |
1453 | - UnRegDeviceNotify(HVTWin); | |
1437 | + if (hDevNotify != NULL && pUnregisterDeviceNotification != NULL) { | |
1438 | + pUnregisterDeviceNotification(hDevNotify); | |
1439 | + hDevNotify = NULL; | |
1440 | + } | |
1454 | 1441 | |
1455 | 1442 | EndKeyboard(); |
1456 | 1443 |