Step to UEFI (161)Print 直接输出 ASCII 的String

之前我在处理 ASCII 的 String 时,都是进行格式化后再输出的,最近偶然间看到了 Print 有一个 %a 参数可以用来直接输出 CHAR8 这样定义的字符串。实验代码如下:

#include  <Uefi.h>
#include  <Library/UefiLib.h>
#include  <Library/ShellCEntryLib.h>
#include  <Library/BaseMemoryLib.h>

int
EFIAPI
main (
  IN int Argc,
  IN CHAR16 **Argv
  )
{

    CHAR8      Buffer[]="This is a simple test\n\r from www.lab-z.com\n\r";

    Print(L"%a", Buffer);
  return EFI_SUCCESS;
}

 

运行结果:

完整的代码下载:
Printa

关于 Print 函数的具体实现,可以在 MdePkg\Library\BasePrintLib\PrintLibInternal.c 中看到。

《Step to UEFI (161)Print 直接输出 ASCII 的String》有4个想法

回复 Neil 取消回复

您的电子邮箱地址不会被公开。 必填项已用 * 标注