Как корректно получить handle консольного приложения?
https://docs.microsoft.com/en-us/windows/console/g...В чем моя ошибка?
Вы решили, что консольное приложение имеет окно в понятиях WinAPI. Это не так.
Дополнение к ответу выше:RegisterDeviceNotification functionParameters
hRecipient [in]
A handle to the window or service that will receive device events for the devices specified in the NotificationFilter parameter. The same window handle can be used in multiple calls to RegisterDeviceNotification.
Services can specify either a window handle or service status handle.
[...]
Remarks:
Any application with a top-level window can receive basic notifications by processing the WM_DEVICECHANGE message. Applications can use the RegisterDeviceNotification function to register to receive device notifications.
Services can use the RegisterDeviceNotification function to register to receive device notifications. If a service specifies a window handle in the hRecipient parameter, the notifications are sent to the window procedure. If hRecipient is a service status handle, SERVICE_CONTROL_DEVICEEVENT notifications are sent to the service control handler.