How use \0 in resource string in resource editor

drjackool 956 Reputation points
2021-02-03T05:25:38.003+00:00

Hi
To using CToolBarCtrl.AddString() function the strings must be separated by \0 (null) and two null in end, but in string table editor when I type for example New\0Open\0\0 the entered string converted to just New. How solve this problem? what is correct escarpment?

Thanks

C++
C++
A high-level, general-purpose programming language, created as an extension of the C programming language, that has object-oriented, generic, and functional features in addition to facilities for low-level memory manipulation.
3,780 questions
0 comments No comments
{count} votes

Accepted answer
  1. RLWA32 45,866 Reputation points
    2021-02-03T13:09:10.627+00:00

    The objective of using CToolBarCtrl::AddString to add multiple strings from a resource seems to be beyond what MFC is designed to accomplish with this function.

    There are a couple of problems with this objective

    1) The resource editor does not support separating multiple strings in a stringtable with \0 as a null character. If you manually edit a .rc file you can create the string resource with embedded nulls. However, subsequent usage of the resource editor will cause the manual edits to be lost. You can avoid this by creating your string resource in MFC's .rc2 file which is not used by the resource editor.

    2) MFC's implementation of CToolBarCtrl::AddString uses CString to load the string resource. The string encapsulated by CString will not be double-null terminated.

    You can use the workaround destribed in 1 above to create the desired array of null-terminated strings. As far as I know LoadString will not load a double null terminator from a resource but this can be worked around by using an adequately sized and initialized buffer to receive the string data. You can then use this buffer with CToolBarCtrl::AddStrings.

    0 comments No comments

1 additional answer

Sort by: Most helpful
  1. Jeanine Zhang-MSFT 9,946 Reputation points Microsoft Vendor
    2021-02-03T06:57:36.813+00:00

    Hi,

    As far as I'm concerned, you could try to use CToolBarCtrl::AddStrings instead of CToolBarCtrl::AddString.

    Best Regards,

    Jeanine


    If the response is helpful, please click "Accept Answer" and upvote it.

    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.


Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.