Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8798969
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T00:12:46+00:00 2026-06-14T00:12:46+00:00

I am going through a previously written code and I found StringCbPrintf() function I

  • 0

I am going through a previously written code and I found StringCbPrintf() function

I found declaration on msdn site like this :

HRESULT StringCbPrintf(
  _Out_  LPTSTR pszDest,
  _In_   size_t cbDest,
  _In_   LPCTSTR pszFormat,
  _In_    ...
);

What is _in_ and _out_ here ?

And why is it needed when we already have sprintf() ?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T00:12:47+00:00Added an answer on June 14, 2026 at 12:12 am

    _In_ and _Out_ (note: neither _in_/_out_ as you wrote, nor __In__/__Out__ with double underscores, as written in some other answer) are so called SAL Annotations. They can be used with /analyze compiler option, and can help identify bugs and problems like buffer overruns etc. with raw C buffers and pointers. In addition to MSDN documentation on SAL, you can read also this blog post.

    Someone ironically (and wrongly) wrote that:

    “In the rest of the world, inputs are const pointers but I guess that
    was too simple. :)”

    missing the fact that SAL is more powerful than that. In fact, with SAL you can also specify the maximum size of a destination buffer, indicating which parameter contains the destination buffer size; e.g. if you open <strsafe.h> header, you can read that the actual SAL annotations used for StringCbPrintfW (the Unicode version of StringCbPrintf) is something like that:

    STRSAFEAPI
    StringCbPrintfW(
        __out_bcount(cbDest) STRSAFE_LPWSTR pszDest,
        __in size_t cbDest,
        __in __format_string STRSAFE_LPCWSTR pszFormat,
        ...)
    {
        ....
    

    Note how the __out_bcount(cbDest) SAL annotation applied to the pszDest parameter specifies that this is a pointer to an output buffer (__out), which size is expressed in bytes (_bcount) by the parameter cbDest. As you can see, this is a rich annotation (richer than simple “const” or “non const“).

    In my opinion, SAL is kind of useless if you write C++ code with robust container classes like std::vector or std::string, which know their own size, etc. But SAL can be useful in C-ish code with raw pointers (like several Win32 APIs).

    About the second part of your question:

    “Why we need StringCbPrintf if we already have sprintf“

    the main reason is that sprintf is an unsafe and buffer overruns-prone function; instead with StringCbPrintf you must specify the maximum size of the destination buffer, and this can help preventing buffer overruns (which are security enemies).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I realise this question has been asked before, but after going through the previously
Going through Javascript documentation, I found the following two functions on a Javascript object
While going through some tutorials, I have encountered lines such as this: ((IDisposable)foo).Dispose(); Ignore
Just going through the sample Scala code on Scala website, but encountered an annoying
I'm trying to access the previously iterated element in a loop going through all
I'm working in the C language and modifying code previously written by someone else.
I was going through some previous posts on CONNECT BY usage. What I need
Going through happstack-lite tutorial : we build functions that have return type of ServerPart
Going through some of my older Delphi projects and upgrading them to D2009, as
Going through the microsoft authentication tutorial listed here they have you create a master

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.