none
How should i correctly pass UNICODE_STRING in RtlStringCbPrintfW / RtlUnicodeStringPrintf as argument? RRS feed

  • Question

  • I am using code:

    WCHAR buffer[256];

    WCHAR* pszTxt = dataPath.Buffer;// dataPath is UNICODE_STIRNG
    int Len = dataPath.Length;

    RtlStringCbPrintfW(buffer, sizeof(buffer), L"%.*s %d", Len, pszTxt, 1);

    This one works.

    But if i use 

    RtlStringCbPrintfW(buffer,
    sizeof(buffer),
    L"%.*s%s", 
    dataPath.Length,
    dataPath.Buffer,
    L"\\");

    Gives me buffer value like  "\Device\HarddiskVolume2\System Volume Information\MyData???"

    What is wrong? Is there version that i can pass UNICODE_STRING directly as argument, without setting out persiction?




    • Edited by The Brans Wednesday, July 9, 2014 1:58 PM correction
    Wednesday, July 9, 2014 1:52 PM

Answers

  • Use RtlUnicodeStringPrintf, that is the call to do what you want.


    Don Burn Windows Filesystem and Driver Consulting Website: http://www.windrvr.com

    Wednesday, July 9, 2014 1:58 PM

All replies

  • Use RtlUnicodeStringPrintf, that is the call to do what you want.


    Don Burn Windows Filesystem and Driver Consulting Website: http://www.windrvr.com

    Wednesday, July 9, 2014 1:58 PM
  • I don't see difference beetwen RtlStringCbPrintfW and RtlUnicodeStringPrintf except RtlUnicodeStringPrintf  stores the string in a UNICODE_STRING structure. But as i can see argements and its processing are the same. So

    WCHAR buffer[256];

    UNICODE_STRING resultPath;
    resultPath.Buffer = buffer;
    resultPath.Length = 0;
    resultPath.MaximumLength = sizeof(buffer);

    RtlUnicodeStringPrintf(&resultPath,
    L"%.*s%s", 
    dataPath.Length,
    dataPath.Buffer, / /"\Device\HarddiskVolume2\System Volume Information\MyData"
    L"\\");

    got same  "\Device\HarddiskVolume2\System Volume Information\MyData???" , just in form of UNICODE_STRING and not PWCHAR. My question was how to use UNICODE_STRING as argument, not result or what is wrong with my code?


    • Edited by The Brans Wednesday, July 9, 2014 2:35 PM correction
    Wednesday, July 9, 2014 2:32 PM
  • Ok for a argument you use %wZ for a Unicode string.


    Don Burn Windows Filesystem and Driver Consulting Website: http://www.windrvr.com

    Wednesday, July 9, 2014 2:40 PM