parragain
July 29th, 1999, 12:13 AM
Hi all,
Since the CString class is not thread safe, I would like to convert CString to char. Do you know how to do that?
Thanks a lot.
Philippe
Burlacu Ovidiu
July 29th, 1999, 01:46 AM
try this
(char*)(LPCSTR)your_string
Regards,
Ovidiu
Tomaz Stih
July 29th, 1999, 03:29 AM
Here's something from online docs.
CString assists you in conserving memory space by allowing two strings sharing the same value also to share the same buffer space. However, if you attempt to change the contents of the buffer directly (not using MFC), you can alter both strings unintentionally. CString provides two member functions, CString::LockBuffer and CString::UnlockBuffer, to help you protect your data. When you call LockBuffer, you create a copy of a string, then set the reference count to -1, which "locks" the buffer. While the buffer is locked, no other string can reference the data in that string, and the locked string will not reference another string. By locking the string in the buffer, you ensure that the string’s exclusive hold on the data will remain intact. When you have finished with the data, call UnlockBuffer to reset the reference count to 1.
So add a critical section or a mutex (if you're going to share mem between processes) then lock it...
Note: LockBuffer will return LPTSTR which is a macro and might not expand to char but to wchar (if you define the _UNICODE symbol).
Regards,
Tomaz
---------------------------------------------
Tomaz Stih, B.Sc.CS tomaz@nameco.com
Ob sotoccju 10 Nameco Group
SI-1000 Ljubljana http://www.nameco.com
Europe