CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 9 of 9
  1. #1
    George2 is offline Elite Member Power Poster
    Join Date
    Oct 2002
    Posts
    4,468

    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

  2. #2
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Hanover Germany
    Posts
    20,396

    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:
    Code:
    #ifdef _UNICODE
    .....
    #define _stprintf   swprintf
    ......
    #else  /* _UNICODE */
    .......
    #define _stprintf   sprintf
    Can we use char* as the 3rd parameter?
    Yes - for _stprintf in a non-unicode build.
    No - for _stprintf in an unicode build.

  3. #3
    George2 is offline Elite Member Power Poster
    Join Date
    Oct 2002
    Posts
    4,468

    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

  4. #4
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Hanover Germany
    Posts
    20,396

    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?

  5. #5
    George2 is offline Elite Member Power Poster
    Join Date
    Oct 2002
    Posts
    4,468

    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.


    regards,
    George

  6. #6
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Hanover Germany
    Posts
    20,396

    Re: about swprintf and _stprintf

    Quote Originally Posted by George2
    It seems that you are an expert and you like to help others.
    No, I am only some of "elite members" here.
    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

  7. #7
    George2 is offline Elite Member Power Poster
    Join Date
    Oct 2002
    Posts
    4,468

    Re: about swprintf and _stprintf

    Hi VictorN,


    Quote Originally Posted by VictorN
    No, I am only some of "elite members" here.
    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

  8. #8
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Hanover Germany
    Posts
    20,396

    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

  9. #9
    George2 is offline Elite Member Power Poster
    Join Date
    Oct 2002
    Posts
    4,468

    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

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured