CString to char*

This is a discussion on CString to char* within the Windows Programming forums, part of the Platform Specific Boards category; I have a function that accepts a parameter of type char*, but I am using a CString type, not a ...

  1. #1
    Unregistered
    Guest

    CString to char*

    I have a function that accepts a parameter of type char*, but I am using a CString type, not a char array, how can I convert it?

    Thank you

  2. #2
    Unregistered
    Guest
    you are using VC++, is it? you may try to replace char * to CString first, perhaps some more for correspondence variables in function. Did you tried? In fact, CString can do easily what char * does(as I know).

  3. #3
    Registered User
    Join Date
    Nov 2001
    Posts
    1,348
    Try this:

    -----
    // YourFunction(char *text);

    CString string("test");
    YourFunction(&static_cast<LPCTSTR>(string));
    -----

    Kuphryn

  4. #4
    Has a Masters in B.S.
    Join Date
    Aug 2001
    Posts
    2,267
    look into CStrings GetBuffer() member function.
    ADVISORY: This users posts are rated CP-MA, for Mature Audiences only.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Inserting a swf file in a windows application
    By face_master in forum Windows Programming
    Replies: 12
    Last Post: 05-03-2009, 11:29 AM
  2. Writing CObjects with Serialization to CArchive
    By ruben_gerad in forum C++ Programming
    Replies: 0
    Last Post: 11-09-2006, 07:25 AM
  3. Problem with Visual C++ Object-Oriented Programming Book.
    By GameGenie in forum C++ Programming
    Replies: 9
    Last Post: 08-29-2005, 11:21 PM
  4. Help with CString class and operator+ overloading
    By skanxalot in forum C++ Programming
    Replies: 2
    Last Post: 10-07-2003, 10:23 AM
  5. Operater overloading - (const char + CString)
    By auth in forum C++ Programming
    Replies: 14
    Last Post: 10-24-2002, 09:22 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21