在网上找到的方法一般是用DeviceIoControl、ReadFile、WriteFile等,但是用这些方法的前提是先调用 CreateFile,这个函数的第一个参数是一个SymbolicLink(例如:"\\\\.\\TestSample"),这个 SymbolicLink一般是在驱动程序中调用IoCreateSymbolicLink创建的,这样的驱动程序一般有类似如下入口例程:
NTSTATUS DriverEntry(IN PDRIVER_OBJECT DriverObject,IN PUNICODE_STRING RegistryPath)
{
    PFILE_OBJECT pLowerFileObject=NULL;
    UNICODE_STRING DeviceName;
    UNICODE_STRING DosDeviceName;
    UNICODE_STRING Name;
    PDEVICE_OBJECT pLowerDeviceObject=NULL;
    PDEVICE_OBJECT pDeviceObject=NULL;
    NTSTATUS Status;
   
    DriverObject->DriverUnload=DriverUnload;
    DriverObject->MajorFunction[IRP_MJ_READ]           = TestSampleRead;
    DriverObject->MajorFunction[IRP_MJ_WRITE]           = TestSampleWrite;
    DriverObject->MajorFunction[IRP_MJ_CREATE]        = TestSampleCreate;
    DriverObject->MajorFunction[IRP_MJ_CLOSE]          = TestSampleClose;
    DriverObject->MajorFunction[IRP_MJ_DEVICE_CONTROL] = TestSampleDeviceControl;
    RtlInitUnicodeString(&DeviceName,gDeviceName);
    RtlInitUnicodeString(&DosDeviceName,gDosDeviceName);
    IoCreateDevice(DriverObject,0,&DeviceName,FILE_DEVICE_UNKNOWN,0,FALSE,&pDeviceObject);
    pDeviceObject->Flags|=DO_BUFFERED_IO;
    Status = IoCreateSymbolicLink(&DosDeviceName,&DeviceName);
    if(Status)
        DbgPrint("IoCreateSymbolicLink Return %0x\n",Status);
    KeInitializeSpinLock(&gSpinLock);
    RtlInitUnicodeString(&Name,gKeventName);
    pMsgKEvent = IoCreateSynchronizationEvent(&Name,&hMsgEvent);
    Status = ObReferenceObjectByHandle(hMsgEvent,EVENT_ALL_ACCESS,*ExEventObjectType,KernelMode,(PVOID*)&gKeventObject,NULL);   
    if(!NT_SUCCESS(Status))
    {
        DbgPrint("SDbgMsg : ObReferenceObjectByHandle\n");
    }
    else
    {
        DbgPrint("gKeventObject = %x pMsgKEvent=%x\n",gKeventObject,pMsgKEvent);
    }
    if(gKeventObject)
        KeClearEvent(gKeventObject);
    if(pMsgKEvent)
        KeResetEvent(pMsgKEvent);
   
    return 0;
}我现在碰到一个这样的驱动程序,它的入口例程如下:
ULONG
DriverEntry (
    IN PDRIVER_OBJECT DriverObject,
    IN PUNICODE_STRING RegistryPath
    )
{
    HW_INITIALIZATION_DATA      HwInitData;
    ULONG                      ReturnValue;    RtlZeroMemory(&HwInitData, sizeof(HwInitData));    HwInitData.HwInitializationDataSize = sizeof(HwInitData);    //
    // Set the Adapter entry points for the driver
    //    HwInitData.HwInterrupt              = NULL; // HwInterrupt;    HwInitData.HwReceivePacket          = AdapterReceivePacket;
    HwInitData.HwCancelPacket          = AdapterCancelPacket;
    HwInitData.HwRequestTimeoutHandler  = AdapterTimeoutPacket;    HwInitData.DeviceExtensionSize      = sizeof(HW_DEVICE_EXTENSION);
    HwInitData.PerRequestExtensionSize  = sizeof(SRB_EXTENSION);
    HwInitData.FilterInstanceExtensionSize = 0;
    HwInitData.PerStreamExtensionSize  = sizeof(STREAMEX);
    HwInitData.BusMasterDMA            = FALSE;
    HwInitData.Dma24BitAddresses        = FALSE;
    HwInitData.BufferAlignment          = 3;
    HwInitData.DmaBufferSize            = 0;    // Don't rely on the stream class using raised IRQL to synchronize
    // execution.  This single paramter most affects the overall structure
    // of the driver.    HwInitData.TurnOffSynchronization  = TRUE;    ReturnValue = StreamClassRegisterAdapter(DriverObject, RegistryPath, &HwInitData);    return ReturnValue;
}
我现在不知道怎么跟这样的驱动程序通讯啊,大虾们帮帮忙啊。

解决方案 »

  1.   

    移到C++去吧, D版估计搞DDK的比较少.
      

  2.   

    DELPHI如果不用DDK,永远不能做出像“冰点”这样的软件了
      

  3.   

    我在VC版也发了帖子,没有得到很好的答复,发在这里主要是想让ly帮着看看,他居然没来到时候散分。
      

  4.   

    应用层和sys通讯,都是使用IRP 请求的,
    即用CreateFile打开sys得到句柄,再调用DeviceIoControl往这个sys,发送I/O控制码 进行通讯所以,sys要能接收并处理,应用层发送过来的IO请求才行,如例子1:
            DriverObject- >MajorFunction[IRP_MJ_READ]                       =   TestSampleRead;
            DriverObject- >MajorFunction[IRP_MJ_WRITE]                       =   TestSampleWrite;
            DriverObject- >MajorFunction[IRP_MJ_CREATE]                 =   TestSampleCreate;
            DriverObject- >MajorFunction[IRP_MJ_CLOSE]                     =   TestSampleClose;
            DriverObject- >MajorFunction[IRP_MJ_DEVICE_CONTROL]   =   TestSampleDeviceControl; 它可以处理的IO请求有:IRP_MJ_READ、IRP_MJ_WRITE,IRP_MJ_DEVICE_CONTROL...而楼主碰到驱动,要通讯的话,也要能接收和处理 IRP
     
      

  5.   

    >> “CreateFile打开sys得到句柄”修改一下:  CreateFile打开 驱动创建的设备,
      

  6.   

    才看见这个贴的
    这个应该是Stream Mini驱动,是物理硬件的驱动,而不是R0的软件(应用)驱动
      

  7.   

    参考
    http://blog.csdn.net/epbon/archive/2006/01/14/578984.aspx