Thread: ListView_SetItemText argument problem

  1. #1
    Registered User
    Join Date
    Oct 2005
    Location
    Brasil
    Posts
    220

    ListView_SetItemText argument problem

    Ok, in my program im working with std::basic_string<WCHAR> and std::basic_string<CHAR> variables, but the function ListView_SetItemText receives the text in the type of LPWSTR. Is there any way of "transforming" that std::basic_string<WCHAR> to a LPWSTR? Or is there another function that i can use LPCWSTR? Thank you in advance.

  2. #2
    Yes, my avatar is stolen anonytmouse's Avatar
    Join Date
    Dec 2002
    Posts
    2,544
    In this case, it is safe to use a cast:
    Code:
    ListView_SetItemText(hwnd, 1, 1, const_cast<LPWSTR>(mystring.c_str()));

  3. #3
    Registered User
    Join Date
    Oct 2005
    Location
    Brasil
    Posts
    220
    Really thank you

  4. #4
    erstwhile
    Join Date
    Jan 2002
    Posts
    2,227
    I prefer to use a temporary array(std::vector) and thereby avoid the const_cast:
    Code:
    std::vector<WCHAR> tmp(mystring.begin(),mystring.end());
    tmp.push_back(L'\0');
    ListView_SetItemText(hwnd,1,1,&tmp[0]);
    CProgramming FAQ
    Caution: this person may be a carrier of the misinformation virus.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. A question related to strcmp
    By meili100 in forum C++ Programming
    Replies: 6
    Last Post: 07-07-2007, 02:51 PM
  2. class as argument problem
    By hallo007 in forum C++ Programming
    Replies: 2
    Last Post: 05-20-2007, 05:23 AM
  3. WS_POPUP, continuation of old problem
    By blurrymadness in forum Windows Programming
    Replies: 1
    Last Post: 04-20-2007, 06:54 PM
  4. Laptop Problem
    By Boomba in forum Tech Board
    Replies: 1
    Last Post: 03-07-2006, 06:24 PM
  5. half ADT (nested struct) problem...
    By CyC|OpS in forum C Programming
    Replies: 1
    Last Post: 10-26-2002, 08:37 AM