Click here to Skip to main content
15,891,184 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: Want to extract all the datas from a list box Pin
Richard MacCutchan16-Mar-11 13:49
mveRichard MacCutchan16-Mar-11 13:49 
GeneralRe: Want to extract all the datas from a list box Pin
Albert Holguin16-Mar-11 14:33
professionalAlbert Holguin16-Mar-11 14:33 
GeneralRe: Want to extract all the datas from a list box Pin
leorex16-Mar-11 22:47
leorex16-Mar-11 22:47 
GeneralRe: Want to extract all the datas from a list box Pin
Richard MacCutchan16-Mar-11 22:58
mveRichard MacCutchan16-Mar-11 22:58 
GeneralRe: Want to extract all the datas from a list box Pin
leorex16-Mar-11 23:08
leorex16-Mar-11 23:08 
GeneralRe: Want to extract all the datas from a list box Pin
Richard MacCutchan17-Mar-11 1:25
mveRichard MacCutchan17-Mar-11 1:25 
GeneralRe: Want to extract all the datas from a list box Pin
leorex17-Mar-11 22:52
leorex17-Mar-11 22:52 
GeneralRe: Want to extract all the datas from a list box Pin
Richard MacCutchan18-Mar-11 0:41
mveRichard MacCutchan18-Mar-11 0:41 
As I said before, you need to be sure that your data fields are pointing at static memory blocks. You have the following line(s) in your code:
TCHAR File_name[MAX_PATH];

//the whole loadfile business here.
int index = SendDlgItemMessage(hwnd, IDC_LIST_COMPARE, LB_ADDSTRING, 0, (LPARAM)str);
sprintf(File_name, "1");//implanted this line just to make sure things goes in. I AM SURE ITS NT AN EMPTY STRING!

SendDlgItemMessage(hwnd, IDC_LIST_COMPARE, LB_SETITEMDATA, (WPARAM)index, (LPARAM)File_name);

However, as soon as you leave this function the variable File_name will be destroyed (because it is on the stack) and your pointer is no longer valid.

You need to do something like:
PTSTR pFile_name;

//the whole loadfile business here.
int index = SendDlgItemMessage(hwnd, IDC_LIST_COMPARE, LB_ADDSTRING, 0, (LPARAM)str);
// get the length of the filename
pFile_name = new TCHAR[the length of the filename + 1];
// copy the filename into the string you just allocated to pFile_name

SendDlgItemMessage(hwnd, IDC_LIST_COMPARE, LB_SETITEMDATA, (WPARAM)index, (LPARAM)pFile_name);

now when you leave this function your filename memory buffer will not be destroyed. You should also remember to delete[] all these memory blocks when you destroy your listbox.
I must get a clever new signature for 2011.

GeneralRe: Want to extract all the datas from a list box Pin
leorex18-Mar-11 15:50
leorex18-Mar-11 15:50 
GeneralRe: Want to extract all the datas from a list box Pin
leorex16-Mar-11 23:01
leorex16-Mar-11 23:01 
QuestionError "member function already defined or declared" Pin
Miwin Solutions16-Mar-11 0:44
Miwin Solutions16-Mar-11 0:44 
QuestionRe: Error "member function already defined or declared" Pin
Niklas L16-Mar-11 1:58
Niklas L16-Mar-11 1:58 
AnswerRe: Error "member function already defined or declared" Pin
Miwin Solutions16-Mar-11 3:41
Miwin Solutions16-Mar-11 3:41 
GeneralRe: Error "member function already defined or declared" Pin
Niklas L16-Mar-11 3:59
Niklas L16-Mar-11 3:59 
GeneralRe: Error "member function already defined or declared" Pin
Miwin Solutions17-Mar-11 7:43
Miwin Solutions17-Mar-11 7:43 
Questionhow to get all handles of process Pin
so0_lanhlung216-Mar-11 0:09
so0_lanhlung216-Mar-11 0:09 
AnswerRe: how to get all handles of process Pin
Code-o-mat16-Mar-11 0:58
Code-o-mat16-Mar-11 0:58 
GeneralRe: how to get all handles of process Pin
so0_lanhlung216-Mar-11 5:10
so0_lanhlung216-Mar-11 5:10 
AnswerRe: how to get all handles of process Pin
Nuri Ismail16-Mar-11 1:04
Nuri Ismail16-Mar-11 1:04 
GeneralRe: how to get all handles of process Pin
so0_lanhlung216-Mar-11 5:09
so0_lanhlung216-Mar-11 5:09 
GeneralRe: how to get all handles of process Pin
Nuri Ismail16-Mar-11 7:00
Nuri Ismail16-Mar-11 7:00 
QuestionHow to write a safe RPC program? Pin
Finix15-Mar-11 23:22
Finix15-Mar-11 23:22 
QuestionCan we put dot [ . ] in the name of Win32 dll Pin
pandit8415-Mar-11 21:55
pandit8415-Mar-11 21:55 
AnswerRe: Can we put dot [ . ] in the name of Win32 dll Pin
_AnsHUMAN_ 15-Mar-11 23:06
_AnsHUMAN_ 15-Mar-11 23:06 
QuestionIssue to write a value 10 using fwrite Pin
cancerion15-Mar-11 20:10
cancerion15-Mar-11 20:10 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.