: : I have variable:
: :
:
: : char * str;
: :
:
: : and m_str is a member of TextBox Control, its type: CString
: : And I want when I click on button, str will get the text in the text box.
: :
: : I used:
: :
:
: : str = m_str;
: :
:
: :
: : I know it's wrong, but I don't have any better idea. Can anyone help me please?
: :
:
: First you need to allocate memory for the char* str to point to.
: For example:
:
:
: char* str = new char[m_str.GetLength() +1];
:
:
: That would allocate enough memory for a C-Style null terminated
: string.
: After that you'll need to copy the contents of the CString m_str
: variable to the newly allocated memory pointed to by the char* str
: variable.
:
: You can look this up on msdn.microsoft.com for more detailed
: information.
:
: Best of luck.
:
:
: We'll be an army of theives
: Of self-freed slaves
: Of mild-mannered maids
: We'll fight with whispers and blades
: So get ready, a new day is dawning
: - The New Wild West -- Jewel
:
: I can suggest you one moreway.
suppose you have a string csString.
and you want to convert it into a char* then....
char *string = new char[csString.GetLength() +1];
string = csString.GetBuffer(csString.GetLength() +1);
csString.ReleaseBuffer();