|
-
May 7th, 2002, 09:41 AM
#1
Thread Starter
Hyperactive Member
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?
Bababooey
Tatatoothy
Mamamonkey
-
May 7th, 2002, 10:12 AM
#2
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...
All the buzzt
 CornedBee
"Writing specifications is like writing a novel. Writing code is like writing poetry."
- Anonymous, published by Raymond Chen
Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.
-
May 7th, 2002, 10:39 AM
#3
Thread Starter
Hyperactive Member
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?
Bababooey
Tatatoothy
Mamamonkey
-
May 10th, 2002, 04:54 AM
#4
No, not yet, this is actually fun 
And you ask good questions, not like "I want to do this app, gimme code!"
All the buzzt
 CornedBee
"Writing specifications is like writing a novel. Writing code is like writing poetry."
- Anonymous, published by Raymond Chen
Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|