CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3
  1. #1
    Join Date
    May 1999
    Posts
    24

    converting string to char.

    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


  2. #2
    Join Date
    Jul 1999
    Location
    Romania - Iasi
    Posts
    558

    Re: converting string to char.

    try this

    (char*)(LPCSTR)your_string





    Regards,
    Ovidiu



  3. #3
    Join Date
    May 1999
    Location
    Slovenia (currently: Germany)
    Posts
    249

    Re: converting string to char.

    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 [email protected]
    Ob sotoccju 10 Nameco Group
    SI-1000 Ljubljana http://www.nameco.com
    Europe



Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured