about swprintf and _stprintf
Hello everyone,
I find that _stprintf is defined to swprintf. And in the prototype of swprintf, the 1st and the 2nd parameters are both wchar_t. I think the other parameters should also be w_chart type, but in some situations, I always find others use char* type (which seems not unicode character type) as the parameter, like,
--------------------
// buffer is wchar_t* type.
_stprintf (buffer, L"%s", (char*)pointer);
--------------------
Definitions from Microsoft,
--------------------
#define _stprintf swprintf
_CRTIMP int __cdecl swprintf(wchar_t *, const wchar_t *, ...);
--------------------
Can we use char* as the 3rd parameter? If we can, why can it (non-unicode type) be compatible with wchar_t type (unicode type)?
thanks in advance,
George
Re: about swprintf and _stprintf
Quote:
Originally Posted by George2
Hello everyone,
I find that _stprintf is defined to swprintf.
..........
Definitions from Microsoft,
--------------------
#define _stprintf swprintf
_CRTIMP int __cdecl swprintf(wchar_t *, const wchar_t *, ...);
--------------------
No, your referemce to Microsoft is not correct.
Correct is:
Quote:
Code:
#ifdef _UNICODE
.....
#define _stprintf swprintf
......
#else /* _UNICODE */
.......
#define _stprintf sprintf
Quote:
Can we use char* as the 3rd parameter?
Yes - for _stprintf in a non-unicode build.
No - for _stprintf in an unicode build.
Re: about swprintf and _stprintf
Thank VictorN,
Quote:
Originally Posted by VictorN
No, your referemce to Microsoft is not correct.
Correct is:
Yes - for _stprintf in a non-unicode build.
No - for _stprintf in an unicode build.
Will there be any errors when UNICODE macro is defined? Could you show me an example please in situation _stprintf (w_char*, L, char*)?
regards,
George
Re: about swprintf and _stprintf
Quote:
Originally Posted by George2
Thank VictorN,
Will there be any errors when UNICODE macro is defined? Could you show me an example please in situation _stprintf (w_char*, L, char*)?
Hi, George!
Why don't you want to investigate it yourself? ;)
Re: about swprintf and _stprintf
Hi VictorN,
Quote:
Originally Posted by VictorN
Hi, George!
Why don't you want to investigate it yourself? ;)
I am not an expert of unicode handling on VC platform. In my mind, it is not safe to use char* as the 3rd parameter if UNICODE is defined. But you know, I am not sure and can not find an example to show my idea. So, could you please show me an example please? It seems that you are an expert and you like to help others. ;) :thumb:
regards,
George
Re: about swprintf and _stprintf
Quote:
Originally Posted by George2
It seems that you are an expert and you like to help others. ;) :thumb:
No, I am only some of "elite members" here. :sick:
And yes, I sometimes try to help others...
But I am sorry, i am currently in a "zeitnot" and can only occutionally access this Forum...
Regards,
Victor
Re: about swprintf and _stprintf
Hi VictorN,
Quote:
Originally Posted by VictorN
No, I am only some of "elite members" here. :sick:
And yes, I sometimes try to help others...
But I am sorry, i am currently in a "zeitnot" and can only occutionally access this Forum...
Regards,
Victor
What is zeitnot?
regards,
George
Re: about swprintf and _stprintf
Quote:
Originally Posted by George2
Hi VictorN,
What is zeitnot?
See this page: :)
http://dict.leo.org/ende?lp=ende&lan...tnot&relink=on
Re: about swprintf and _stprintf
Thanks VictorN! I got it. I means short of time. It is non-English words. Cool!
Quote:
Originally Posted by VictorN
regards,
George