Archived

This topic is now archived and is closed to further replies.

Luctus

SendMessage & delete crashes..

Recommended Posts

Luctus    584
Not very good with the Windows API and I''ve probably done something really stoopid.. This is a snippet from my app.
char *line;
					
len = SendMessage(GetDlgItem(g_hWnd, IDC_TABLE), LB_GETTEXTLEN, (WPARAM)i, 0 );
line = new char[len];

SendMessage(GetDlgItem(g_hWnd, IDC_TABLE), LB_GETTEXT, (WPARAM)i, (LPARAM)line );
fprintf( outfile, "%s\n", line );

delete [] line;
And it crashes something horribly at the delete operator, what am I doing wrong? -Luctus
Statisticly seen, most things happens to other people. [Mail]

Share this post


Link to post
Share on other sites
CodeMunkie    805
Are you sure it is delete that is causing the error? The only thing I can think of is that the listbox index you are passing might not be valid and so LB_GETTEXTLEN is returning LB_ERR which you aren''t checking for. I don''t know what LB_ERR is defined as, but if it is negative and you are using it to allocate memory with, well, fun things can happen .

Share this post


Link to post
Share on other sites
Guest Anonymous Poster   
Guest Anonymous Poster
LB_GETTEXTLEN: "The return value is the length of the string, in TCHARs, *excluding the terminating null character*"

LB_GETTEXT: "The buffer must have sufficient space for the string *and a terminating null character*"

Share this post


Link to post
Share on other sites