【Windows驱动开发-存储数据提供应用层读写】

兼容任意版本的Windows。 应用程可读写驱动内存。主要做XDMA驱动开发的。就把驱动这块吃熟悉了。这里就是举个简单的例子有意向合作的小伙伴可以加我抠口:2+3+2+9+2+0+4+3+9+1或私信我

驱动安装好后如图:DataDriver

应用程代码片段:

HANDLE hdRead, hdWrite;
    if (!OpenDevice(hdRead, hdWrite)){
        return -1;
    }

    DWORD ret = 0;
    int bufSize = 1024;

    /向驱动写入数据/
    char buf[1024];

    //初始化数据为0x1
    memset(buf, 0x1, 1024);
    if(!WriteFile(hdWrite, buf, 1024, &ret, NULL))
    {
        printf("WriteFile failed!!! error=%u\n", GetLastError());
        goto __END;
    }

    //偏移1024再写入
    if (INVALID_SET_FILE_POINTER == SetFilePointer(hdWrite, 1024, NULL, FILE_BEGIN)) {
        return -2;
    }
    //初始化数据为0x2
    memset(buf, 0x2, 1024);
    if (!WriteFile(hdWrite, buf, 1024, &ret, NULL))
    {
        printf("WriteFile failed!!! error=%u\n", GetLastError());
        goto __END;
    }

    /从驱动读取数据/
    //读驱动数据1MB

    if (!ReadFile(hdRead, buf, bufSize, &ret, NULL))
    {
        printf("read failed!!! error=%u\n", GetLastError());
        goto __END;
    }

    //打印buf...

    //偏移1MB再读取一次1MB
    if (INVALID_SET_FILE_POINTER == SetFilePointer(hdRead, 1024, NULL, FILE_BEGIN)) {
        return -3;
    }

    if (!ReadFile(hdRead, buf, bufSize, &ret, NULL))
    {
        printf("[%d]read failed!!! error=%u\n", GetLastError());
    }
    
    //打印buf...

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

xwzj264

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值