stdio的printf和Windows驱动程序 [英] stdio's printf and Windows Driver

查看:135
本文介绍了stdio的printf和Windows驱动程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在驱动程序代码(DDK)中使用 printf,因此我包括了stdio.h。但是编译器会说:

I want to use "printf" in driver code (DDK), therefore I've included stdio.h. But the compiler says:

error LNK2001: unresolved external symbol __imp__printf

有什么想法吗?我在某处看到不可能-但这太糟糕了-我简直不敢相信。为什么我不能在内核代码中使用标准的C例程?

Any ideas? I seen somewhere that it is not possible - but that's awful - I can't believe it. Why can't I use standard C routines in kernel code?


  1. 诸如printf之类的C函数来自静态cstd.lib或AFAIK do n't不是吗?

  2. 那为什么WDK会为我提供stdio.h?


推荐答案

Windows内核仅支持部分标准C运行时。特别是高级功能—例如文件流,控制台I / O和网络—不支持。相反,您需要使用本机内核API来实现类似的功能。

The Windows kernel only supports part of the standard C runtime. In particular, high-level functionality — like file streams, console I/O, and networking — is not supported. Instead, you need to use native kernel APIs for similar functionality.

WDK包含stdio.h的原因是因为提供了C运行时的某些功能您的方便。例如,您可以使用 memcmp (尽管首选本机 RtlCompareMemory )。 Microsoft尚未选择CRT标头来#ifdef剔除内核模式下不可用的位和片段。一旦您有了编写内核驱动程序的经验,就可以掌握内核中可能发生的事情,以及可能行不通的事情。

The reason that stdio.h is included with the WDK is because some parts of the C runtime are provided for your convenience. For example, you can use memcmp (although the native RtlCompareMemory is preferred). Microsoft has not picked through the CRT headers to #ifdef out the bits and pieces that are not available in kernel mode. Once you develop some experience writing kernel drivers, you'll get the hang of what's possible in the kernel, and what probably won't work.

级别的问题:您可能正在寻找某种调试/记录机制。您确实有两个选择:

To address your high-level question: you're probably looking for some debug/logging mechanism. You really have two options:


  1. DbgPrintEx 是最容易使用的。它基本上是printf的一个替代项(尽管在运行> = DISPATCH_LEVEL时,您需要注意某些类型的字符串插入)。输出将输出到调试器,或者,如果愿意,输出到 DbgView

  2. WPP 是工业强度选项。初始学习曲线非常陡峭(尽管WDK中有示例)。但是,它非常灵活(例如,您可以创建自己的尖叫声,例如 Print(我的IP地址为:%!IPV4!,ip); ),以及它非常快(Microsoft在大多数Windows组件的非调试版本中提供了WPP跟踪)。

  1. DbgPrintEx is the easiest to use. It's basically a drop-in for printf (although you need to be careful about certain types of string inserts when running >=DISPATCH_LEVEL). Output goes to the debugger, or, if you like, to DbgView.
  2. WPP is the industrial-strength option. The initial learning curve is pretty steep (although there are samples in the WDK). However, it is very flexible (e.g., you can create your own shrieks, like Print("My IP address is: %!IPV4!", ip);), and it is very fast (Microsoft ships WPP tracing in the non-debug builds of most Windows components).

这篇关于stdio的printf和Windows驱动程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆