Click here to Skip to main content
15,886,638 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I would like to display the contents of an array, with a "0x00" embedded, in a dialog using SetWindowText(), AfxMessageBox(), or something similar.

Example Array
unsigned char y[] = {0x21, 0x00, 0x21};

The issue I am having is that the contents of the array are being treated as a CString and so only the first element is being displayed instead of the entire array. What is the correct way to display the entire array with an embedded 0x00? Thanks.
Posted
Comments
Mohibur Rashid 27-May-15 22:04pm    
If you are using CString, then you will face the problem because CString is null terminated string whereas your second character is null. You will have to create the output string by length.
barneyman 27-May-15 22:33pm    
there is no representation for the ascii null character, so even if you could get the MsgBox or SetWinText to take a pascal string it wouldn't know how to display it

i'd advise having some function that takes the array, and the size, and returns a string with the null converted to some other character

1 solution

You must use the right formatter options and format it as a string. Like that

C++
text.Format("0x%2X", theByte);


Read the documentation
 
Share this answer
 
Comments
CPallini 28-May-15 3:26am    
5.
turnrod 28-May-15 9:28am    
That works. Thanks!

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900