I am a novice in C and trying to amend and compile an EDK2 EFI program.
The program portion I want to change has a function MsgLog which takes a Char16 * variable and uses this to write to a log file.
The current code has this
MsgLog("SomeText ...%r\n", Status);
Status is an EFI_STATUS which can be "Success" or "Not Found". I.E., you can get the following in a log file:
SomeText ...Success
or
SomeText ...Not Found
I will like to change this to:
SomeText ...Success : ABC
or
SomeText ...Not Found : XYZ
I have loaded : ABC or : XYZ into a Char16 * variable (has to be Char16 * to match other restrictions by the function used to set this)
I have then tried various options to append it to the string such as
MsgLog("SomeText ...%r%s\n", Status, myVariable);
and
MsgLog("SomeText ...%r%r\n", Status, myVariable);
but I end up with
SomeText ...Success<null string>
and
SomeText ...Not Found<null string>
I am not sure what formatting placeholder I am supposed to use or whether or how I should cast myVariable to some other appropriate format and would appreciate some pointers.
Please note that this is a wider program of which I am changing a small portion and I don't have scope to define different variable types.
EDIT: Added Context
ORIGINAL WORKING CODE
EFI_STATUS Funct_A()
{
EFI_STATUS Status;
//Funct_B returns EFI_SUCCESS or EFI_NOT_FOUND
Status = Funct_B();
MsgLog("SomeText ...%r\n", Status);
PROBLEM CODE
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".
myVariable? How is it defined? How is it initialized? How isStatusdefined and initialized? - KamilCukStatusis working fine and is not part of the issue. It returns Success or Not Found as needed and this is in the log.myVariableis what I have added and what I need to see how to add to the string. It is set in a different function which I don't have scope to amend. The question is whether a CHAR16 Variable can be added to a string as shown or not. - DayoIt returnsA variable can't "return". Sure, that's great it "works", just more context would be helpful.myVariable is what I have addedHow and where and what exactly have you added? (ie. how it's defined and initialized or assigned)whether a CHAR16It'sCHAR16orChar16? It just would be really helpful if you would create an minimal reproducible example, even with your current not working code. - KamilCuk