_vscwprintf equivalent in the kernel?

Is there an equivalent to _vscwprintf in the kernel? In other words, given a *printf format string and its parameters, is there a function that can tell me the number of wchar_ts that the final string will occupy?

If there is not, this is a terrible oversight of the kernel, since it would add a grand total of like 128 bytes to the kernel >.<

It sucks, but all the *printf variants return a fixed value, -1, if you try passing in a null pointer as the destination or an intentionally-too-small string. It would be nice if there were a way to ask for the output size, like almost every other API in the entirety of Windows NT.

Melissa

It seems there is no ‘_vscwprintf’-lookalike provided by the ‘ntstrsafe.lib’. At least i don’t know about.

But there is a workaround.
Although not documented it appears the ‘_vscwprintf’ itself is placed in the ‘libcntpr.lib’. But the implementation seems to be broken a bit, since anyone using that is faced with the linker error:
“unresolved external symbol ___lookuptable_s”.
And it seems this symbol indeed is not defined anywhere in WDK-supplied libs.

So in turn you can copy-paste the definition of ‘__lookuptable_s’ into your project from the VisualStudio crt sources:
$(VISUAL_STUDIO_DIRECTORY)/VC/crt/src/output.c

I’ve checked this appeared to be working at Win7/WinRT with at least VS2013/WDK8.1. And don’t ever forget this is just an ugly hack.

Well, most of us would use RtlUncodeStringVPrintf or
RtlUncodeStringVPrintfEx. Since UNICODE_STRINGS are counted strings you do
get the value, and this is the native form in the kernel.

Don Burn
Windows Filesystem and Driver Consulting
Website: http://www.windrvr.com
Blog: http://msmvps.com/blogs/WinDrvr

-----Original Message-----
From: xxxxx@lists.osr.com
[mailto:xxxxx@lists.osr.com] On Behalf Of xxxxx@gmail.com
Sent: Sunday, May 18, 2014 12:53 AM
To: Windows System Software Devs Interest List
Subject: [ntdev] _vscwprintf equivalent in the kernel?

Is there an equivalent to _vscwprintf in the kernel? In other words, given
a *printf format string and its parameters, is there a function that can
tell me the number of wchar_ts that the final string will occupy?

If there is not, this is a terrible oversight of the kernel, since it would
add a grand total of like 128 bytes to the kernel >.<

It sucks, but all the *printf variants return a fixed value, -1, if you try
passing in a null pointer as the destination or an intentionally-too-small
string. It would be nice if there were a way to ask for the output size,
like almost every other API in the entirety of Windows NT.

Melissa


NTDEV is sponsored by OSR

Visit the list at: http://www.osronline.com/showlists.cfm?list=ntdev

OSR is HIRING!! See http://www.osr.com/careers

For our schedule of WDF, WDM, debugging and other seminars visit:
http://www.osr.com/seminars

To unsubscribe, visit the List Server section of OSR Online at
http://www.osronline.com/page.cfm?name=ListServer

StringCb/CchPrintf family can do this.

wrote in message news:xxxxx@ntdev…
> Is there an equivalent to _vscwprintf in the kernel? In other words, given a *printf format string and its parameters, is there a function that can tell me the number of wchar_ts that the final string will occupy?
>
> If there is not, this is a terrible oversight of the kernel, since it would add a grand total of like 128 bytes to the kernel >.<
>
> It sucks, but all the *printf variants return a fixed value, -1, if you try passing in a null pointer as the destination or an intentionally-too-small string. It would be nice if there were a way to ask for the output size, like almost every other API in the entirety of Windows NT.
>
> Melissa
>

Maxim S. Shatskih (xxxxx@storagecraft.com) wrote:

StringCb/CchPrintf family can do this.

How do you do this? The documentation states that they handle passing NULL destination parameters in a very specific fashion that does not return the “would have” length. Instead, they cause the routine to treat the input as an empty string.

Melissa