How to use string functions with winapi?

So, I am making a program (in win32) that picks an episode of a TV show randomly. I want to make a function string EpisodePicker() that will pick the episode, and call it when the user clicks a button. I would like a function that returns a word, basically. How would I do that?
Exactly like you posted have a function returning std::string

something like
std::string EpisodePicker()
    //some code 
    std::string episode = "Clone Wars 2-4"; //implement your logic to pick this
    //some other code
    return episode;
Last edited on
Oh, yeah, thank you. But I figured it out. I was trying to use CreateWindow() to show static text on the screen, and I just made the EpisodePicker() function to return a LPSTR, which is the parameter for the window name. Thank you anyway.
Last edited on
You can keep confusion at bay by always remembering that the WinApi functions all take pointers to null terminated strings as parameters, not string objects, as in Std C++ Lib String Class or wstring. Its of course convenient to perform string manipulations on string objects, but in passing one to a WinApi function you need to use the string::c_str() method. When retrieving a string pointer from a WinApi function, assigning it to a std::string will give you something you can perhaps more easily work with.
Topic archived. No new replies allowed.