我是 C 的新手,正在尝试修改和编译 EDK2 EFI 程序。
我要更改的程序部分有一个函数MsgLog
,它接受一个Char16 *
变量并使用它来写入日志文件。
当前代码有这个
MsgLog("SomeText ...%r\n", Status);
状态是一个 EFI_STATUS,可以是“成功”或“未找到”。IE,您可以在日志文件中获取以下内容:
SomeText ...Success
或者
SomeText ...Not Found
我想将其更改为:
SomeText ...Success : ABC
或者
SomeText ...Not Found : XYZ
我已经加载 : ABC
或 : XYZ
进入一个Char16 *
变量(必须是 Char16 * 以匹配用于设置它的函数的其他限制)
然后我尝试了各种选项将其附加到字符串中,例如
MsgLog("SomeText ...%r%s\n", Status, myVariable);
和
MsgLog("SomeText ...%r%r\n", Status, myVariable);
但我最终得到
SomeText ...Success<null string>
和
SomeText ...Not Found<null string>
我不确定我应该使用什么格式占位符,或者我是否应该或如何将 myVariable 转换为其他适当的格式,并希望得到一些指示。
请注意,这是一个更广泛的程序,我正在更改其中的一小部分,并且我没有定义不同变量类型的范围。
编辑:添加上下文
原始工作代码
EFI_STATUS Funct_A()
{
EFI_STATUS Status;
//Funct_B returns EFI_SUCCESS or EFI_NOT_FOUND
Status = Funct_B();
MsgLog("SomeText ...%r\n", Status);
问题代码
EFI_STATUS Funct_A()
{
EFI_STATUS Status;
CHAR16 *myVariable = NULL;
//Funct_B returns EFI_SUCCESS or EFI_NOT_FOUND
Status = Funct_B();
// From some header file, I see "#define SPrint UnicodeSPrint". Not 100% sure it is the relevant one
// From other code implementations, I know SPrint takes "CHAR16" as first variable.
if (!EFI_ERROR (Status)) {
SPrint (myVariable, 255, L" : ABC");
} else {
SPrint (myVariable, 255, L" : XYZ");
}
MsgLog("SomeText ...%r%r\n", Status, myVariable);
// MsgLog is a bit of a rabbit's warren and I can't provide all the background but it expects "CHAR16".