NO

Author Topic: Basic question on use of StringCchPrintf function.  (Read 6071 times)

EdPellesC99

  • Guest
Basic question on use of StringCchPrintf function.
« on: April 22, 2010, 12:24:39 AM »
   Though I read that the StringCchPrintf function replaces the printf function, as I understand it ..... It actually seems to just add a prior step.
With StringCchPrintf, you are safely writing a string to a buffer.

You must then use the printf function (or another deprecated variation) to dump the buffer to the console window. Correct?

  If true, wouldn't you usually need to have #define strsafe_no_deprecate ?  
.....in order to print the string to the console window?
 
There is no way to use StringCchPrintf alone to both write the buffer and dump it to the console window, am I right?

  Thanks, Ed
« Last Edit: April 22, 2010, 12:34:00 AM by EdPellesC99 »

Offline AlexN

  • Global Moderator
  • Member
  • *****
  • Posts: 394
    • Alex's Link Sammlung
Re: Basic question on use of StringCchPrintf function.
« Reply #1 on: April 22, 2010, 08:39:33 AM »
As I understand the StringCchPrintf-function, you can use it in this way:
Code: [Select]
#include <stdio.h>
#include <strsafe.h>

int main()
{
char Str[20];

if (S_OK == StringCchPrintfA(Str, sizeof(Str),"Hello %s", "world"))
{
puts(Str);
}

return 0;
}
You also can look at: http://msdn.microsoft.com/en-us/library/ms647541%28VS.85%29.aspx
« Last Edit: April 22, 2010, 09:10:42 AM by AlexN »
best regards
 Alex ;)

JohnF

  • Guest
Re: Basic question on use of StringCchPrintf function.
« Reply #2 on: April 22, 2010, 01:50:10 PM »
Ed, the StringCchPrintf function does not act like the printf function, it is more like the sprintf function.

John

EdPellesC99

  • Guest
Re: Basic question on use of StringCchPrintf function.
« Reply #3 on: May 16, 2010, 06:28:10 AM »
Tx Alex,

And John

I forgot to ck notify me of replies. (Just got this).

and yes I see John .....

Tx, Ed