Click here to Skip to main content
15,913,325 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: How to set Member variable as extern variable Pin
Jokcy16-Mar-11 15:16
Jokcy16-Mar-11 15:16 
GeneralRe: How to set Member variable as extern variable Pin
Albert Holguin16-Mar-11 15:23
professionalAlbert Holguin16-Mar-11 15:23 
QuestionDynamic Product Name - Visual Deployment Project Pin
pix_programmer16-Mar-11 2:59
pix_programmer16-Mar-11 2:59 
AnswerRe: Dynamic Product Name - Visual Deployment Project Pin
Albert Holguin16-Mar-11 15:37
professionalAlbert Holguin16-Mar-11 15:37 
AnswerRe: Dynamic Product Name - Visual Deployment Project Pin
Albert Holguin16-Mar-11 15:43
professionalAlbert Holguin16-Mar-11 15:43 
GeneralRe: Dynamic Product Name - Visual Deployment Project Pin
pix_programmer16-Mar-11 18:34
pix_programmer16-Mar-11 18:34 
GeneralRe: Dynamic Product Name - Visual Deployment Project Pin
Albert Holguin17-Mar-11 4:09
professionalAlbert Holguin17-Mar-11 4:09 
QuestionReverse Search in CRichEditCtrl class Pin
Rakesh516-Mar-11 2:07
Rakesh516-Mar-11 2:07 
AnswerRe: Reverse Search in CRichEditCtrl class Pin
Cool_Dev16-Mar-11 3:36
Cool_Dev16-Mar-11 3:36 
AnswerRe: Reverse Search in CRichEditCtrl class Pin
Richard MacCutchan16-Mar-11 3:37
mveRichard MacCutchan16-Mar-11 3:37 
QuestionWant to extract all the datas from a list box Pin
leorex16-Mar-11 0:55
leorex16-Mar-11 0:55 
AnswerRe: Want to extract all the datas from a list box Pin
Hans Dietrich16-Mar-11 1:47
mentorHans Dietrich16-Mar-11 1:47 
AnswerRe: Want to extract all the datas from a list box Pin
Richard MacCutchan16-Mar-11 1:54
mveRichard MacCutchan16-Mar-11 1:54 
GeneralRe: Want to extract all the datas from a list box Pin
Albert Holguin16-Mar-11 9:38
professionalAlbert Holguin16-Mar-11 9:38 
GeneralRe: Want to extract all the datas from a list box Pin
Richard MacCutchan16-Mar-11 12:45
mveRichard MacCutchan16-Mar-11 12:45 
GeneralRe: Want to extract all the datas from a list box Pin
Albert Holguin16-Mar-11 13:40
professionalAlbert Holguin16-Mar-11 13:40 
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 

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.