Hello, I have a problem which is most likely a simple problem, but neverthe less still a problem for me. I am using the Listbox in Win32 / C++ and when getting the selected text from my listbox the string returned is just garbage. It is a handle to a struct or similar?
Below is the code and an example of what I get.
std::string Listbox::GetSelected() {
int index = -1;
int count = 0;
count = SendMessage(control, LB_GETSELCOUNT, 0, 0);
if(count > 0) {
index = SendMessage(control, LB_GETSEL, 0, 0);
}
return GetString(index);
}
std::string Listbox::GetString(int index) {
int count = 0;
int length = 0;
char * text;
if(index >= 0) {
count = GetItemCount();
if(index < count) {
length = SendMessage(control, LB_GETTEXTLEN, (WPARAM)index, 0);
text = new char[length + 1];
SendMessage(control, LB_GETTEXT, (WPARAM)index, (LPARAM)text);
}
}
std::string s(text);
delete[] text;
return s;
}
GetItemCount just does that. It just gets the number of items currently in the listbox.
The string I was grabbing from the Listbox is "Test String" and it returned ¨±é» Tzã
Any help is appericated, thanks.
Ok, I narrowed it down to my GetSelected function as GetString returns the correct string.