Re: Passing a string between dialogs
"Kahlua" <kahlua@right.here> ha scritto nel messaggio
news:RafHj.42$ta2.41@trndny05...
CStrings dont work for me because any byte in the string (array) can be 0h
I guess I need to be able to pass and Array of bytes (12 bytes max) to
MyDlg2
Please explain how I can do this.
The CString method below works fine unless there's a 0h in the string.
void CMyDlg::OnButton()
{
CMyDlg dlg;
dlg.m_string = MyData;
if ( dlg.DoModal() == IDOK)
MyData = dlg.m_string;
}
Continuing my previous post about std::vector<BYTE>, and putting it in the
context of above code snippet, I would make your "m_string" data field an
std::vector<BYTE> ('ByteArray', using typedef from aforementioned post), and
I would also rename it, like m_byteData (m_*string* is kind of misguiding,
IMHO... a string typically terminates with '\0'...), e.g.
class CMyDlg
{
public:
...
ByteArray m_byteData;
...
};
Also 'MyData' should be of type 'ByteArray'.
The assignment with operator= works fine, and if your array is not big (12
bytes is fine), there are no performance problems on modern hardware.
If you have a bigger array, I would suggest you to avoid deep copies due to
operator=, and use pointers (or references) instead.
But it seems like a useless complication for your particular problem.
Moreover, I prefer embedding data fields into get/set accessor methods,
instead of exposing public data fields, e.g.
class CMyDlg
{
public:
...
//
// Access ByteArray field using get/set accessors
//
void SetBytes( const ByteArray & source )
{
m_byteData = source;
}
const ByteArray & GetBytes() const
{
return m_byteData;
}
...
// ByteArray instance is private
private:
ByteArray m_byteData;
};
Giovanni