首页 > 系统相关 >Windows驱动开发环境搭建测试HelloWorld

Windows驱动开发环境搭建测试HelloWorld

时间:2022-10-21 16:45:40浏览次数:84  
标签:status WDF Windows object DRIVER HelloWorld KmdfHelloWorldEvtDeviceAdd NTSTATUS 

主要参考官方链接: https://learn.microsoft.com/zh-cn/windows-hardware/drivers/gettingstarted/writing-a-very-small-kmdf--driver 其中注意修改点:

  1. 双虚拟机安装好windows10系统(MSDN我告诉你下载)。
  1. vmware 虚拟机设置。
  1. 需要自己下载dbgview64.exe。DebugView - Windows Sysinternals
  1. 需要修改目标计算机调试信息打印注册表。
Windows Registry Editor Version 5.00 [HKEY_LOCAL_MACHINE/SYSTEM/CurrentControlSet/Control/Session Manager/Debug Print Filter] DEFAULT=dword:0000000f
  1. 微软示例驱动程序打印函数KdPrintEx 修改为 KdPrint。
  1. 编译生成拷贝到目标计算机,打开debugview(对应平台),使用devcon直接安装驱动可以看到打印调试信息。
调试驱动安装和打印信息:    
 1 #include <ntddk.h>
 2 #include <wdf.h>
 3 
 4 
 5 DRIVER_INITIALIZE DriverEntry;
 6 EVT_WDF_DRIVER_DEVICE_ADD KmdfHelloWorldEvtDeviceAdd;
 7 DRIVER_UNLOAD DriverUnload;
 8 
 9 NTSTATUS
10 DriverEntry(
11     _In_ PDRIVER_OBJECT     DriverObject,
12     _In_ PUNICODE_STRING    RegistryPath
13 )
14 {
15     // NTSTATUS variable to record success or failure
16     NTSTATUS status = STATUS_SUCCESS;
17 
18     // Allocate the driver configuration object
19     WDF_DRIVER_CONFIG config;
20 
21     // Print "Hello World" for DriverEntry
22     //KdPrintEx((DPFLTR_IHVDRIVER_ID, DPFLTR_WARNING_LEVEL, "KmdfHelloWorld: DriverEntry\n"));
23     KdPrint(("DriverEntry CxlHello....\r\n"));
24     //DbgPrint("Hello World ccll\r\n");
25 
26     // Initialize the driver configuration object to register the
27     // entry point for the EvtDeviceAdd callback, KmdfHelloWorldEvtDeviceAdd
28     WDF_DRIVER_CONFIG_INIT(&config,
29         KmdfHelloWorldEvtDeviceAdd
30     );
31 
32     // Finally, create the driver object
33     status = WdfDriverCreate(DriverObject,
34         RegistryPath,
35         WDF_NO_OBJECT_ATTRIBUTES,
36         &config,
37         WDF_NO_HANDLE
38     );
39     return status;
40 }
41 
42 NTSTATUS
43 KmdfHelloWorldEvtDeviceAdd(
44     _In_    WDFDRIVER       Driver,
45     _Inout_ PWDFDEVICE_INIT DeviceInit
46 )
47 {
48     // We're not using the driver object,
49     // so we need to mark it as unreferenced
50     UNREFERENCED_PARAMETER(Driver);
51 
52     NTSTATUS status;
53 
54     // Allocate the device object
55     WDFDEVICE hDevice;
56 
57     // Print "Hello World"
58     //KdPrintEx((DPFLTR_IHVDRIVER_ID, DPFLTR_WARNING_LEVEL, "KmdfHelloWorld: KmdfHelloWorldEvtDeviceAdd\n"));
59     KdPrint(("Driver Config Init CxlHello....\r\n"));
60     //DbgPrint("Hello World ccxx\r\n");
61 
62     // Create the device object
63     status = WdfDeviceCreate(&DeviceInit,
64         WDF_NO_OBJECT_ATTRIBUTES,
65         &hDevice
66     );
67     return status;
68 }

 

刚开始学习windows驱动开发,官方文档不友好,自己琢磨,记录得比较乱,有需要交流可以留言。  

标签:status,WDF,Windows,object,DRIVER,HelloWorld,KmdfHelloWorldEvtDeviceAdd,NTSTATUS,
From: https://www.cnblogs.com/chenxiaolinembed/p/16813962.html

相关文章

  • 如何搭建自己的CI/CD平台:Gitlab+Jenkins+Docker+Harbor+K8s集群搭建CICD平台(持续集
    如何搭建自己的CI/CD平台:Gitlab+Jenkins+Docker+Harbor+K8s集群搭建CICD平台(持续集成部署Hexo博客Demo)写在前面聊聊CICD的环境搭建以及一个基于Hexo的博客系统在C......
  • Proxmox ve(Pve) 安装windows server
    1.安装proxmoxve点击直达官网地址 下载下来如果下载速度太慢可以去安装个IDMhttps://www.52pojie.cn/thread-1013874-1-1.html 然后需要制作u盘启动器下载一个Rufus......
  • Windows 平台下 LiteIDE 的安装和使用
    1.安装Go语言并设置环境变量参考博客《Windows平台下Go语言的安装和环境变量设置》。2.MinGW的下载和安装Windows下的Go调试还需要安装MinGW。2.1下载安装工具......
  • windows下卸载oracle步骤
    windows下卸载oracle步骤  有道是,oracle安装容易卸载难。博主总结了一些卸载步骤,供大家参考 1.删除oracle注册表信息.运行regedit,删除注册表项  HKEY_LOCAL_MACHINE/......
  • Windows 远程桌面优化设置
    修改默认端口(可选)启动注册表编辑器(在“搜索”框中键入regedit);导航到以下注册表子项:HKEY_LOCAL_MACHINE\System\CurrentControlSet\Control\TerminalServer\WinSt......
  • 基础篇:windows常用命令
    1.windows常用系统命令cd[进入目录]dir[列出当前目录文件]echo+打印内容[打印命令]echo123>1.txt[打印内容到文本]type+文件内容[查看文件]......
  • Windows打开回收站的几种方式
    1.桌面双击回收站图标打开回收站,简单、快捷、方便,但在打开多个窗口时候还要最小化这些窗口以显示桌面,如果还要迅速恢复这些窗口的话也算是麻烦2.磁盘每个分区根目录下都......
  • windows操作
    1、提取文件名dirC:\Users\admin\Desktop\数据/b>C:\Users\admin\Desktop\temp.xls2、EXCEL=IF(A2=A3,B2&"\"&C3,B2)=COUNTIF($A$2:$A2,A2)3、笔记本双路由添加rout......
  • Kubernetes_02_从零开始搭建k8s集群(亲测可用)
    @[toc]一、前言本文讲述从零开始搭建k8s集群,均使用国内镜像,版本均统一,使用两个虚拟机,一个主节点,一个从节点,保证k8s一次搭建成功。注意:Kubernetes,简称K8s,是用8代替名字中间的......
  • 7款Windows下桌面神器,1款只有15k,还秒杀微软自带
    这篇文章的主角,是你天天都会用到的桌面任务栏:可別小看位于桌面底部的这小小一栏!三顿做了一番优化,它不仅变得颜值超高,而且大幅提升了我的工作效率。是的,三顿要给大家分......