Panel 发表于 2021-12-29 16:38

实现一个简单的通讯框架的时候出现问题

如题,新手刚入门驱动开发,在写一个0环写3环的通讯demo时,出现了问题,3环无法成功通讯0环

0环代码#include "ntifs.h"
#define DEVICEC_NAME L"\\device\\Device"
#define LINK_NAME L"\\dosdevices\\links"
VOID UnloadDriver(PDRIVER_OBJECT driver)
{
        DbgPrint("Succes");
       
}

NTSTATUS DispatchCreate(PDEVICE_OBJECT pDeviceObject, PIRP pIrp)
{
        DbgPrint("收到请求");
        pIrp->IoStatus.Status = STATUS_SUCCESS;
        pIrp->IoStatus.Information = 0;
        IoCompleteRequest(pIrp, IO_NO_INCREMENT);
        return STATUS_SUCCESS;
}

NTSTATUS DriverEntry(PDRIVER_OBJECT pDriver, PUNICODE_STRING reg_path)
{
        DbgPrint("succes");
        UNICODE_STRING pdevicename = { 0 };
        UNICODE_STRING plinkname = { 0 };
        PDEVICE_OBJECT Device = NULL;
        NTSTATUS status = STATUS_SUCCESS;
        RtlInitUnicodeString(&pdevicename, DEVICEC_NAME);
        RtlInitUnicodeString(&plinkname, LINK_NAME);
        status = IoCreateDevice(pDriver, 0, &pdevicename, FILE_DEVICE_UNKNOWN, 0, TRUE, &Device);
        if (!NT_SUCCESS(status))
        {
                DbgPrint("错误代码:%ld", status);
                return 0;
        }
        Device->Flags |= DO_BUFFERED_IO;
        status = IoCreateSymbolicLink(&plinkname, &pdevicename);
        if (!NT_SUCCESS(status))
        {
                DbgPrint("错误代码:%ld", status);
                return 0;
        }
        pDriver->MajorFunction = DispatchCreate;
        pDriver->DriverUnload = UnloadDriver;
        return STATUS_SUCCESS;
}

3环代码
#include "stdio.h"
#include "windows.h"


#define DEVICE_LINK_NAME L"\\\\.\\links"

int main()
{
        HANDLE hDriver = CreateFile(DEVICE_LINK_NAME, GENERIC_ALL, 0, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
        if (hDriver == INVALID_HANDLE_VALUE)
        {
                printf("错误代码:%d", GetLastError());
                system("pause");
                return 1;
        }
}
页: [1]
查看完整版本: 实现一个简单的通讯框架的时候出现问题