USB 장치가 연결되거나 해제 됐을 때는 이벤트를 처리하는 방법을 여기 저기 찾아 보다가 대충 적어봅니다.
1. 메시지 맵 등록
메시지 맵에 이벤트를 함수와 연결 시킨다.
BEGIN_MESSAGE_MAP(CDlg, CDialog)
ON_MESSAGE(WM_DEVICECHANGE, fnDeviceChange)
END_MESSAGE_MAP()
BEGIN_MESSAGE_MAP(CDlg, CDialog)
ON_MESSAGE(WM_DEVICECHANGE, fnDeviceChange)
END_MESSAGE_MAP()
BEGIN_MESSAGE_MAP(CDlg, CDialog) ON_MESSAGE(WM_DEVICECHANGE, fnDeviceChange) END_MESSAGE_MAP()
2. 이벤트를 받을 장치를 등록한다.
장치 등록은 RegisterForDeviceNotifications()함수를 이용한다
void CDlg::RegisterForDeviceNotifications()
{
DEV_BROADCAST_DEVICEINTERFACE DevBroadcastDeviceInterface;
HDEVNOTIFY DeviceNotificationHandle;
DevBroadcastDeviceInterface.dbcc_size = sizeof(DevBroadcastDeviceInterface);
DevBroadcastDeviceInterface.dbcc_devicetype
void CDlg::RegisterForDeviceNotifications()
{
DEV_BROADCAST_DEVICEINTERFACE DevBroadcastDeviceInterface;
HDEVNOTIFY DeviceNotificationHandle;
DevBroadcastDeviceInterface.dbcc_size = sizeof(DevBroadcastDeviceInterface);
DevBroadcastDeviceInterface.dbcc_devicetype
void CDlg::RegisterForDeviceNotifications() { DEV_BROADCAST_DEVICEINTERFACE DevBroadcastDeviceInterface; HDEVNOTIFY DeviceNotificationHandle; DevBroadcastDeviceInterface.dbcc_size = sizeof(DevBroadcastDeviceInterface); DevBroadcastDeviceInterface.dbcc_devicetype