Jan 20th, 2003, 06:24 PM
#1
Thread Starter
Frenzied Member
String Buffer sizing
Im using a LB_GETTEXTLEN to get the length on of the string but how do i make the buffer ?
VB Code:
[b]{ADDED}
char *sBuf = "";
int iList;
int iSel;
int iSel2;
iSel = ::SendMessage(list,LB_GETCURSEL,0,0);
iSel2 = ::SendMessage(list,LB_GETTEXTLEN,iSel,0);
::SendMessage(list,LB_GETTEXT,iSel,sBuf);
// iList = ::GetWindowTextLength(list);
// ::GetWindowText(list,sBuf,iList);
::SetWindowText(edit,sBuf);[/b]
- JayWare
Live to love. Not to Hate
Im to busy to have a site. But I got one and still working on it.
http://dre3k.net/
Jan 20th, 2003, 06:28 PM
#2
Frenzied Member
use either:
new
or calloc() (malloc() in disguise)
after using the buffer, call either delete or free(). delete goes with new, free() with calloc().
Jan 20th, 2003, 06:29 PM
#3
Thread Starter
Frenzied Member
Forgot to say ima newB how do i do it? can i get a sample. Ill research on msdn but can u gimme a sample please thanks
- JayWare
Live to love. Not to Hate
Im to busy to have a site. But I got one and still working on it.
http://dre3k.net/
Jan 20th, 2003, 06:37 PM
#4
Thread Starter
Frenzied Member
Look at the attached youll see my error
Attached Images
Last edited by JasonLpz; Jan 20th, 2003 at 06:40 PM .
- JayWare
Live to love. Not to Hate
Im to busy to have a site. But I got one and still working on it.
http://dre3k.net/
Jan 20th, 2003, 07:19 PM
#5
PowerPoster
PHP Code:
{ ADDED }
char * sBuf = [ color = red ] NULL [/ color ];
int iList ;
int iSel ;
int iSel2 ;
iSel = :: SendMessage (list, LB_GETCURSEL , 0 , 0 );
iSel2 = :: SendMessage (list, LB_GETTEXTLEN , iSel , 0 );
// Allocate & Initialize the string buffer
sBuf = ( char *) LocalAlloc ( LPTR , iSel2 + 1 );
memset ( sBuf , '\0' , iSel2 + 1 );
:: SendMessage (list, LB_GETTEXT , iSel , ( LPARAM ) sBuf );
// iList = ::GetWindowTextLength(list);
// ::GetWindowText(list,sBuf,iList);
:: SetWindowText ( edit , sBuf );
// Free the used resource
LocalFree (( char *) sBuf );
You can use others function to allocate the string buffer like mention by jim mcnamara.
Jan 20th, 2003, 08:01 PM
#6
Thread Starter
Frenzied Member
Thats the error i get with your code:
VB Code:
[color="#0000A0"]Error[/color] C2137: [color="#0000A0"]Empty[/color] character constant
ON:
VB Code:
memset(sBuf, [color="#00A000"]'', iSel2+1);[/color]
- JayWare
Live to love. Not to Hate
Im to busy to have a site. But I got one and still working on it.
http://dre3k.net/
Jan 20th, 2003, 08:13 PM
#7
PowerPoster
The sample code is filered by the PHP tag,
it should be
VB Code:
memset(sBuf, '\0', iSel2+1);
Jan 20th, 2003, 08:22 PM
#8
Thread Starter
Frenzied Member
YES Great thanks
if i had a million dollars.......
..........I'd be rich! lol
- JayWare
Live to love. Not to Hate
Im to busy to have a site. But I got one and still working on it.
http://dre3k.net/
Jan 21st, 2003, 11:37 AM
#9
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.
Jan 21st, 2003, 01:08 PM
#10
Thread Starter
Frenzied Member
are you talking to me? Cuz if you are you must not be very smart, because what do you think im trying to do?
- JayWare
Live to love. Not to Hate
Im to busy to have a site. But I got one and still working on it.
http://dre3k.net/
Jan 22nd, 2003, 05:59 AM
#11
You are using MFC without knowing enough C++ for it. That's what you're trying to do, and it's a bad thing.
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.
Jan 26th, 2003, 08:13 AM
#12
Hyperactive Member
Isn't LocalAlloc depreciated science Windows 3.1?
Use HeapAlloc() instead.
Jan 26th, 2003, 08:17 AM
#13
Monday Morning Lunatic
Deprecated Depreciated means losing its value...in this case partially correct though.
{Local,Global}Alloc were designed more around 16-bit programming, yes.
I refuse to tie my hands behind my back and hear somebody say "Bend Over, Boy, Because You Have It Coming To You".
-- Linus Torvalds
Jan 26th, 2003, 04:31 PM
#14
Yep, those two were built around the special memory model of Winx.x. I'm happy I didn't program back then.
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.
Jan 26th, 2003, 07:56 PM
#15
PowerPoster
, i should change my code to use HeapAlloc from now.
Jan 27th, 2003, 11:45 AM
#16
The only one of those function that should still be used is LocalFree, because FormatMessage allocates with LocalAlloc if requested to allocate memory.
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