Adding variable to a listbox

So I'm trying to add a variable's value to a listbox but it isn't working at all...

here is the code:
 
SendMessage(hList,LB_ADDSTRING,0,(LPARAM)Var );

I'm pretty sure I have to typecast to LPCWSTR but it doesn't work... it displays weird characters, so anyone has any clue how to achieve this?
No one?... I really need some hep with this.
The single line you posted looks fine. But what's in Var?

Can you replace Var with a string literal and get that to work?
Var could be a number preferably unsigned long ( it could be a signed int ), but it does not work :/ for example:
1
2
3
4
5
int var = 123;

SendMessage(hList,LB_ADDSTRING,0,(LPARAM)(LPCWSTR)Var );
OR
SendMessage(hList,LB_ADDSTRING,0,(LPARAM)Var );


it has to be converted to LPCWSTR but there is no method of converting it, typecasting does not work...

it just displays {

I can't find anyway to actually convert it.
The LPARAM must be a string, so you've got to convert your number Var to a string. You could use ltoa, sprintf/_swprintf/_stprintf, ostringstream/wostringstream, ...

e.g.

1
2
3
4
5
6
int Var = 123;

TCHAR buffer[16] = _T("");
_stprintf(buffer, _T("%d"), Var);

SendMessage(hList,LB_ADDSTRING,0,(LPARAM)buffer );


or

1
2
3
4
5
6
int Var = 123;

ostringstream oss; // from <sstream>, use wostringstream if compiling UNICODE
oss << Var;

SendMessage(hList,LB_ADDSTRING,0,(LPARAM)oss.str().c_str() );


etc...
Last edited on
Thank you very much sir ( late reply cause I had to go somewhere)

Thank you, my problem was Unicode as you stated :/ I'm going to change from the stupid UNICODE...
Last edited on
Topic archived. No new replies allowed.