Пример #1
0
NOTIFY_HANDLE CService::RegisterDeviceHandleNotification(HANDLE DeviceHandle)
{
    NOTIFY_HANDLE handle = NULL;

#ifdef UNIVERSAL
    CM_NOTIFY_FILTER filter;
    CONFIGRET cr;

    ::ZeroMemory(&filter, sizeof(filter));
    filter.cbSize = sizeof(filter);
    filter.FilterType = CM_NOTIFY_FILTER_TYPE_DEVICEHANDLE;
    filter.u.DeviceHandle.hTarget = DeviceHandle;

    cr = CM_Register_Notification(&filter, this,
        CService::DeviceNotificationCallback, &handle);

    if (cr != CR_SUCCESS)
    {
        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;
}
Пример #2
0
DWORD
GetDevicePath(
    _In_ LPGUID InterfaceGuid,
    _Out_ LPWSTR * DevicePath
    )
{
    CONFIGRET cmRet = CR_SUCCESS;
    ULONG interfaceListSize = 0;

    *DevicePath = NULL;

    cmRet = CM_Get_Device_Interface_List_Size_Ex(&interfaceListSize, InterfaceGuid, 0, CM_GET_DEVICE_INTERFACE_LIST_PRESENT, NULL);
    if (cmRet != CR_SUCCESS) {
        goto exit;
    }

    *DevicePath = (LPWSTR)LocalAlloc(LMEM_ZEROINIT, interfaceListSize * sizeof((*DevicePath)[0]));
    if (NULL == *DevicePath) {
        cmRet = CR_OUT_OF_MEMORY;
        goto exit;
    }

    cmRet = CM_Get_Device_Interface_List_Ex(InterfaceGuid, 0, *DevicePath, interfaceListSize, CM_GET_DEVICE_INTERFACE_LIST_PRESENT, NULL);

exit:

    if (cmRet != CR_SUCCESS) {
        if (NULL != *DevicePath) {
            LocalFree(*DevicePath);
            *DevicePath = NULL;
        }
    }
    
    return CM_MapCrToWin32Err(cmRet, ERROR_UNIDENTIFIED_ERROR);
}
Пример #3
0
NOTIFY_HANDLE CService::RegisterDeviceInterfaceNotification()
{
    NOTIFY_HANDLE handle = NULL;

#ifdef UNIVERSAL
    CM_NOTIFY_FILTER filter;
    CONFIGRET cr;

    ::ZeroMemory(&filter, sizeof(filter));
    filter.cbSize = sizeof(filter);
    filter.FilterType = CM_NOTIFY_FILTER_TYPE_DEVICEINTERFACE;
    filter.u.DeviceInterface.ClassGuid = GUID_DEVINTERFACE_BALLOON;

    cr = CM_Register_Notification(&filter, this,
        CService::DeviceNotificationCallback, &handle);

    if (cr != CR_SUCCESS)
    {
        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;
}