функция HidRegisterMinidriver

Тема в разделе "WASM.NT.KERNEL", создана пользователем Llirik, 28 май 2011.

  1. Llirik

    Llirik Member

    Публикаций:
    0
    Регистрация:
    18 июл 2008
    Сообщения:
    468
    Пожалуйста, расскажите по-подробнее об этой функции. Что она конкретно делает? И что означает член DevicesArePolled в структуре HID_MINIDRIVER_REGISTRATION ?
     
  2. shchetinin

    shchetinin Member

    Публикаций:
    0
    Регистрация:
    27 май 2011
    Сообщения:
    715
    Грубого говоря, региструруешь свой драйвер для получения запросов IOCTL\ INTERNAL _IOCTL от HID (IOCTL_HID_GET_DEVICE_DESCRIPTOR, IOCTL_HID_READ_REPORT and etc.)

    DevicesArePolled если установлен, то система может слать не сколько запросов (IOCTL_HID_READ_REPORT), если нет соотвественно только один. Не которые устройства не могут обробатывать несколько запросов(клавиатура, кей уп, даун) ... Но если устройство может, то пул(не сколько запросов) дает хороший прирост производительности ..

    П.С Но в целом лучше прочитайте матчасть: http://msdn.microsoft.com/en-us/library/ff543301%28v=VS.85%29.aspx
     
  3. Llirik

    Llirik Member

    Публикаций:
    0
    Регистрация:
    18 июл 2008
    Сообщения:
    468
    Мне тогда HidRegisterMinidriver вообще не понадобилась, а сейчас она мне действительно нужна, к тому же я тогда программировал на МАСМе, сейчас же программирую на Си, но линкер выдаёт:
    Собираю в DDK 7600.16385.1, который я сам встроил в Visual studio 2015:crazy:
    MKJoy.c
    Код (Text):
    1. #include "MKJoy.h"
    2.  
    3. NTSTATUS DriverEntry (PDRIVER_OBJECT, PUNICODE_STRING);
    4.  
    5. #ifdef ALLOC_PRAGMA
    6. #pragma alloc_text (INIT, DriverEntry)
    7. #pragma alloc_text (PAGE, MKJoy_AddDevice)
    8. #pragma alloc_text (PAGE, MKJoy_PnP)
    9. #pragma alloc_text (PAGE, MKJoy_Power)
    10. #pragma alloc_text (PAGE, MKJoy_Unload)
    11. #endif
    12.  
    13. NTSTATUS
    14. DriverEntry (
    15.   IN  PDRIVER_OBJECT  DriverObject,
    16.   IN  PUNICODE_STRING RegistryPath
    17.   )
    18. /*++
    19. Routine Description:
    20.  
    21.   Initialize the entry points of the driver.
    22.  
    23. --*/
    24. {
    25.   ULONG i;
    26.    HID_MINIDRIVER_REGISTRATION reg;
    27.   //
    28.   // Fill in all the dispatch entry points with the pass through function
    29.   // and the explicitly fill in the functions we are going to intercept
    30.   //
    31.   for (i = 0; i <= IRP_MJ_MAXIMUM_FUNCTION; i++) {
    32.   DriverObject->MajorFunction[i] = MKJoy_DispatchPassThrough;
    33.   }
    34.   DriverObject->MajorFunction [IRP_MJ_PNP] =  MKJoy_PnP;
    35.   DriverObject->MajorFunction [IRP_MJ_POWER] =  MKJoy_Power;
    36.   DriverObject->DriverUnload = MKJoy_Unload;
    37.   DriverObject->DriverExtension->AddDevice = MKJoy_AddDevice;
    38.  
    39.    RtlZeroMemory(&reg, sizeof(reg));
    40.    reg.Revision = HID_REVISION;
    41.    reg.DriverObject = DriverObject;
    42.    reg.RegistryPath = RegistryPath;
    43.    reg.DeviceExtensionSize = 0; //sizeof(DEVICE_EXTENSION) + GetSizeofGenericExtension();
    44.    reg.DevicesArePolled = FALSE;
    45.  
    46.    return HidRegisterMinidriver(&reg);
    47. }
    48.  
    49. NTSTATUS
    50. MKJoy_AddDevice(
    51.   IN PDRIVER_OBJECT  Driver,
    52.   IN PDEVICE_OBJECT  PDO
    53.   )
    54. {
    55.   PAGED_CODE();
    56.  
    57.   return STATUS_SUCCESS;
    58. }
    59.  
    60. NTSTATUS
    61. MKJoy_Complete(
    62.   IN PDEVICE_OBJECT  DeviceObject,
    63.   IN PIRP  Irp,
    64.   IN PVOID  Context
    65.   )
    66. /*++
    67. Routine Description:
    68.  
    69.   Generic completion routine that allows the driver to send the irp down the
    70.   stack, catch it on the way up, and do more processing at the original IRQL.
    71.  
    72. --*/
    73. {
    74.   PKEVENT  event;
    75.  
    76.   event = (PKEVENT) Context;
    77.  
    78.   //
    79.   // We could switch on the major and minor functions of the IRP to perform
    80.   // different functions, but we know that Context is an event that needs
    81.   // to be set.
    82.   //
    83.   KeSetEvent(event, 0, FALSE);
    84.  
    85.   //
    86.   // Allows the caller to use the IRP after it is completed
    87.   //
    88.   return STATUS_MORE_PROCESSING_REQUIRED;
    89. }
    90.  
    91. NTSTATUS
    92. MKJoy_DispatchPassThrough(
    93.   IN PDEVICE_OBJECT DeviceObject,
    94.   IN PIRP Irp
    95.   )
    96. /*++
    97. Routine Description:
    98.  
    99.   Passes a request on to the lower driver.
    100.  
    101. Considerations:
    102.  
    103.   If you are creating another device object (to communicate with user mode
    104.   via IOCTLs), then this function must act differently based on the intended
    105.   device object.  If the IRP is being sent to the solitary device object, then
    106.   this function should just complete the IRP (becuase there is no more stack
    107.   locations below it).  If the IRP is being sent to the PnP built stack, then
    108.   the IRP should be passed down the stack.
    109.  
    110.   These changes must also be propagated to all the other IRP_MJ dispatch
    111.   functions (such as create, close, cleanup, etc.) as well!
    112.  
    113. --*/
    114. {
    115.   PIO_STACK_LOCATION irpStack = IoGetCurrentIrpStackLocation(Irp);
    116.  
    117.   //
    118.   // Pass the IRP to the target
    119.   //
    120.   IoSkipCurrentIrpStackLocation(Irp);
    121.   return IoCallDriver(GET_NEXT_DEVICE_OBJECT(DeviceObject), Irp);
    122. }  
    123. NTSTATUS
    124. MKJoy_PnP(
    125.   IN PDEVICE_OBJECT DeviceObject,
    126.   IN PIRP Irp
    127.   )
    128. /*++
    129.  
    130. Routine Description:
    131.  
    132.   This routine is the dispatch routine for plug and play irps
    133.  
    134. Arguments:
    135.  
    136.   DeviceObject - Pointer to the device object.
    137.  
    138.   Irp - Pointer to the request packet.
    139.  
    140. Return Value:
    141.  
    142.   Status is returned.
    143.  
    144. --*/
    145. {
    146.   PHID_DEVICE_EXTENSION  devExt;
    147.   PIO_STACK_LOCATION  irpStack;
    148.   NTSTATUS  status = STATUS_SUCCESS;
    149.   KIRQL  oldIrql;
    150.   KEVENT  event;  
    151.  
    152.   PAGED_CODE();
    153.  
    154.   devExt = (PHID_DEVICE_EXTENSION) DeviceObject->DeviceExtension;
    155.   irpStack = IoGetCurrentIrpStackLocation(Irp);
    156.  
    157.   switch (irpStack->MinorFunction) {
    158.   case IRP_MN_START_DEVICE: {
    159.  
    160.   //
    161.   // The device is starting.
    162.   //
    163.   // We cannot touch the device (send it any non pnp irps) until a
    164.   // start device has been passed down to the lower drivers.
    165.   //
    166.   IoCopyCurrentIrpStackLocationToNext(Irp);
    167.   KeInitializeEvent(&event,
    168.   NotificationEvent,
    169.   FALSE
    170.   );
    171.  
    172.   IoSetCompletionRoutine(Irp,
    173.   (PIO_COMPLETION_ROUTINE) MKJoy_Complete,
    174.   &event,
    175.   TRUE,
    176.   TRUE,
    177.   TRUE); // No need for Cancel
    178.  
    179.   status = IoCallDriver(devExt->NextDeviceObject, Irp);
    180.  
    181.   if (STATUS_PENDING == status) {
    182.   KeWaitForSingleObject(
    183.   &event,
    184.   Executive, // Waiting for reason of a driver
    185.   KernelMode, // Waiting in kernel mode
    186.   FALSE, // No allert
    187.   NULL); // No timeout
    188.   }
    189.   Irp->IoStatus.Status = status;
    190.   Irp->IoStatus.Information = 0;
    191.   IoCompleteRequest(Irp, IO_NO_INCREMENT);
    192.  
    193.   break;
    194.   }
    195.   default:
    196.   //
    197.   // Here the filter driver might modify the behavior of these IRPS
    198.   // Please see PlugPlay documentation for use of these IRPs.
    199.   //
    200.   IoSkipCurrentIrpStackLocation(Irp);
    201.   status = IoCallDriver(devExt->NextDeviceObject, Irp);
    202.   break;
    203.   }
    204.  
    205.   return status;
    206. }
    207.  
    208. NTSTATUS
    209. MKJoy_Power(
    210.   IN PDEVICE_OBJECT  DeviceObject,
    211.   IN PIRP  Irp
    212.   )
    213. /*++
    214.  
    215. Routine Description:
    216.  
    217.   This routine is the dispatch routine for power irps  Does nothing except
    218.   record the state of the device.
    219.  
    220. Arguments:
    221.  
    222.   DeviceObject - Pointer to the device object.
    223.  
    224.   Irp - Pointer to the request packet.
    225.  
    226. Return Value:
    227.  
    228.   Status is returned.
    229.  
    230. --*/
    231. {
    232.   PHID_DEVICE_EXTENSION  devExt;
    233.  
    234.   PAGED_CODE();
    235.  
    236.   devExt = (PHID_DEVICE_EXTENSION) DeviceObject->DeviceExtension;
    237.   PoStartNextPowerIrp(Irp);
    238.   IoSkipCurrentIrpStackLocation(Irp);
    239.   return PoCallDriver(devExt->NextDeviceObject, Irp);
    240. }
    241.  
    242. VOID
    243. MKJoy_Unload(
    244.   IN PDRIVER_OBJECT Driver
    245.   )
    246. /*++
    247.  
    248. Routine Description:
    249.  
    250.   Free all the allocated resources associated with this driver.
    251.  
    252. Arguments:
    253.  
    254.   DriverObject - Pointer to the driver object.
    255.  
    256. Return Value:
    257.  
    258.   None.
    259.  
    260. --*/
    261.  
    262. {
    263.   PAGED_CODE();
    264.  
    265.   UNREFERENCED_PARAMETER(Driver);
    266.  
    267.   ASSERT(NULL == Driver->DeviceObject);
    268. }
    MKJoy.h
    Код (Text):
    1. #ifndef MKJoy_H
    2. #define MKJoy_H
    3.  
    4. #include "ntddk.h"
    5. #include "wdm.h"
    6. //#include "hidtoken.h"
    7. #include "hidusage.h"
    8. #include "hidport.h"
    9. //#include "gameport.h"
    10.  
    11.  
    12. #define GET_NEXT_DEVICE_OBJECT(DO) (((PHID_DEVICE_EXTENSION)(DO)->DeviceExtension)->NextDeviceObject)
    13.  
    14. /*typedef struct _DEVICE_EXTENSION
    15. {
    16.  
    17. } DEVICE_EXTENSION, *PDEVICE_EXTENSION;
    18. */
    19. //
    20. // Prototypes
    21. //
    22.  
    23. NTSTATUS
    24. MKJoy_AddDevice(
    25.   IN PDRIVER_OBJECT DriverObject,
    26.   IN PDEVICE_OBJECT BusDeviceObject
    27.   );
    28.  
    29.  
    30. NTSTATUS
    31. MKJoy_DispatchPassThrough(
    32.   IN PDEVICE_OBJECT DeviceObject,
    33.   IN PIRP Irp
    34.   );
    35.  
    36. NTSTATUS
    37. MKJoy_PnP (
    38.   IN PDEVICE_OBJECT DeviceObject,
    39.   IN PIRP Irp
    40.   );
    41.  
    42. NTSTATUS
    43. MKJoy_Power (
    44.   IN PDEVICE_OBJECT DeviceObject,
    45.   IN PIRP Irp
    46.   );
    47.  
    48. VOID
    49. MKJoy_Unload (
    50.   IN PDRIVER_OBJECT DriverObject
    51.   );
    52.  
    53. #endif  // MKJoy_H
    Подскажите, пожалуйста, почему возникает эта ошибка?
     
  4. Llirik

    Llirik Member

    Публикаций:
    0
    Регистрация:
    18 июл 2008
    Сообщения:
    468
    Не линкеровалось из-за этой строки в makefile
    Код (Text):
    1. RESOURCE_ONLY_DLL = 1
    Я её написал, чтобы компилировать драйвер без ссылки на *.pdb