-
Casting argh
I have the following function prototype:
CString MyFunction(void) const
it returns the correct string i desire.
When i want to add the string to a listctrl i cast it the following
way:
lvi.pszText = (LPTSTR)(LPCTSTR)MyFunction;
when i do this, i get garbage characters (Ý to be exact)
However, i have another function prototype
const CString& MyFunction(void) const
which works correctly when i cast it. Any help?
-
Strange. You basically shouldn't cast a CString to LPTSTR anyway, but in case of the pszText member of LVITEM it should be ok. Are you sure that the function that returns the CString works correctly? You should maybe pass a non-const reference of a CString to the function and let it just set the value (pass-by-reference). If it still doesn't work the function must have a serious problem.
Wait a moment. Is it just a typo in this post, or is your code really
lvi.pszText = (LPTSTR)(LPCTSTR)MyFunction;
?
In this case you didn't call the function but rather converted it's address to LPTSTR!!!
BTW, C++ functions don't need the void in the parameter list...
-
i just put void there so you were aware that the function doesn't alter any variable passed to it.
as far as the altering the function address...you're right, it was a
typo, i got it to work :P
thx CornedBee yet again...are you gonna start charging me?
-
No, not yet, this is actually fun ;)
And you ask good questions, not like "I want to do this app, gimme code!" :mad: :D