Jump to content

UsbRegisterChangeNotification: Difference between revisions

From EDM2
No edit summary
W.m.brul (talk | contribs)
 
(4 intermediate revisions by the same user not shown)
Line 1: Line 1:
==Description==
==Description==
Registers semaphores for a generic attach/detach notification of USB devices.
Registers semaphores for generic attach/detach notification of USB devices.


==Syntax==
==Syntax==
<pre>
<pre>
ulrc=UsbRegisterChangeNotification(pNotifyID,hDeviceAdded,hDeviceRemoved)
ulrc = UsbRegisterChangeNotification(pNotifyID,hDeviceAdded,hDeviceRemoved)
 
</pre>
</pre>


==Parameters==
==Parameters==
; pNotifyID :  
; pNotifyID : the address of the variable to receive the Notification Identifier.


; hDeviceAdded :  
; hDeviceAdded : the handle of the event semaphore to be posted on device attach.


; hDeviceRemoved :  
; hDeviceRemoved : the handle of the event semaphore to be posted on device detach.


==Return Code==
==Return Code==
 
<pre>
0x0000 - NO_ERROR
</pre>
===Errors===
===Errors===
  [0000] - NO_ERROR
<pre>
  [0006] - ERROR_INVALID_HANDLE
0x0006 - ERROR_INVALID_HANDLE
  [0057] - ERROR_INVALID_PARAMETER
0x0057 - ERROR_INVALID_PARAMETER
  [005F] - ERROR_INTERRUPT (95)
0x005F - ERROR_INTERRUPT
  [0067] - ERROR_TOO_MANY_SEM_REQUESTS (103)
0x0067 - ERROR_TOO_MANY_SEM_REQUESTS
  [0069] - ERROR_SEM_OWNER_DIED (105)
0x0069 - ERROR_SEM_OWNER_DIED
  [1B58] - USB_NOT_INIT (7000)
0x1B58 - USB_NOT_INIT
  [1B59] - USB_ERROR_NO_MORE_NOTIFICATTIONS (7001)
0x1B59 - USB_ERROR_NO_MORE_NOTIFICATTIONS
  [FF06] - ERROR_INVALID_HANDLE
0xFF06 - ERROR_INVALID_HANDLE
  [FF1F] - ERROR_GEN_FAILURE
0xFF1F - ERROR_GEN_FAILURE
  [FF57] - ERROR_INVALID_PARAMETER
0xFF57 - ERROR_INVALID_PARAMETER
  [FF64] - ERROR_TOO_MANY_SEMAPHORES
0xFF64 - ERROR_TOO_MANY_SEMAPHORES
 
</pre>
==Remarks==
==Remarks==


==Example Code==
==Example Code==
<pre>
<pre>
//Code Snippet - UsbRegisterChangeNotification
{
  APIRET ulrc;
  HEV hDeviceAdded;
  HEV hDeviceRemoved;
  PHEV phDeviceAdded;
  PHEV phDeviceRemoved;
  PUSBNOTIFY pNotifyID;
  ULONG ulTimeout = 8000;
  USBNOTIFY NotifyID;
  //acquire semaphores
  phDeviceAdded = &hDeviceAdded;
  ulrc = DosCreateEventSem(NULL,phDeviceAdded,DC_SEM_SHARED,FALSE);
  printf("\nDosCreateEventSem - ulrc: 0x%04X (%hu)",ulrc,ulrc);
  phDeviceRemoved = &hDeviceRemoved;
  ulrc = DosCreateEventSem(NULL,phDeviceRemoved,DC_SEM_SHARED,FALSE);
  printf("\nDosCreateEventSem - ulrc: 0x%04X (%hu)",ulrc,ulrc);
  pNotifyID = &NotifyID;
  ulrc = UsbRegisterChangeNotification(pNotifyID,hDeviceAdded,hDeviceRemoved);
  printf("\nUsbRegisterChangeNotification - ulrc: 0x%04X (%hu)",ulrc,ulrc);
  //await attach device event
  ulrc = DosWaitEventSem(hDeviceAdded,ulTimeout);
  printf("\nDosWaitEventSem - ulrc: 0x%04X (%hu)",ulrc,ulrc);
  if (!ulrc) //success
  {
    printf(" - obtained Attach Notification");
  }
  //await detach device event
  ulrc = DosWaitEventSem(hDeviceRemoved,ulTimeout);
  printf("\nDosWaitEventSem - ulrc: 0x%04X (%hu)",ulrc,ulrc);
  if (!ulrc) //success
  {
    printf(" - obtained Detach Notification");
  }
}
</pre>
</pre>


==Related Functions==
==Related Functions==
* [[UsbRegisterDeviceNotification]]
* [[UsbDeregisterNotification]]
* [[UsbOpen]]


[[Category:USBCalls]]
[[Category:USBCalls]]

Latest revision as of 17:24, 12 February 2017

Description

Registers semaphores for generic attach/detach notification of USB devices.

Syntax

ulrc = UsbRegisterChangeNotification(pNotifyID,hDeviceAdded,hDeviceRemoved)

Parameters

pNotifyID
the address of the variable to receive the Notification Identifier.
hDeviceAdded
the handle of the event semaphore to be posted on device attach.
hDeviceRemoved
the handle of the event semaphore to be posted on device detach.

Return Code

0x0000 - NO_ERROR

Errors

0x0006 - ERROR_INVALID_HANDLE
0x0057 - ERROR_INVALID_PARAMETER
0x005F - ERROR_INTERRUPT
0x0067 - ERROR_TOO_MANY_SEM_REQUESTS
0x0069 - ERROR_SEM_OWNER_DIED
0x1B58 - USB_NOT_INIT
0x1B59 - USB_ERROR_NO_MORE_NOTIFICATTIONS
0xFF06 - ERROR_INVALID_HANDLE
0xFF1F - ERROR_GEN_FAILURE
0xFF57 - ERROR_INVALID_PARAMETER
0xFF64 - ERROR_TOO_MANY_SEMAPHORES

Remarks

Example Code

//Code Snippet - UsbRegisterChangeNotification
{
  APIRET ulrc;
  HEV hDeviceAdded;
  HEV hDeviceRemoved;
  PHEV phDeviceAdded;
  PHEV phDeviceRemoved;
  PUSBNOTIFY pNotifyID;
  ULONG ulTimeout = 8000;
  USBNOTIFY NotifyID;

  //acquire semaphores
  phDeviceAdded = &hDeviceAdded;
  ulrc = DosCreateEventSem(NULL,phDeviceAdded,DC_SEM_SHARED,FALSE);
  printf("\nDosCreateEventSem - ulrc: 0x%04X (%hu)",ulrc,ulrc);
  phDeviceRemoved = &hDeviceRemoved;
  ulrc = DosCreateEventSem(NULL,phDeviceRemoved,DC_SEM_SHARED,FALSE);
  printf("\nDosCreateEventSem - ulrc: 0x%04X (%hu)",ulrc,ulrc);

  pNotifyID = &NotifyID;
  ulrc = UsbRegisterChangeNotification(pNotifyID,hDeviceAdded,hDeviceRemoved);
  printf("\nUsbRegisterChangeNotification - ulrc: 0x%04X (%hu)",ulrc,ulrc);

  //await attach device event
  ulrc = DosWaitEventSem(hDeviceAdded,ulTimeout);
  printf("\nDosWaitEventSem - ulrc: 0x%04X (%hu)",ulrc,ulrc);
  if (!ulrc) //success
  {
    printf(" - obtained Attach Notification");
  }

  //await detach device event
  ulrc = DosWaitEventSem(hDeviceRemoved,ulTimeout);
  printf("\nDosWaitEventSem - ulrc: 0x%04X (%hu)",ulrc,ulrc);
  if (!ulrc) //success
  {
    printf(" - obtained Detach Notification");
  }
}

Related Functions