Normaly I would post this in the C++ board, but I think the problem is windows related.
I have class witch can add nodes and brows through a linked list.
the function that adds the node looks like this:
some words are dutch, I'll translate to clearefy (sp?)Code:bool CMP3LIST::AddToList(int length,char title[MAX_PATH],char filepath[MAX_PATH]) { if (firsttime) { nieuw=(MP3STRUCTLIST *)malloc(sizeof(MP3STRUCTLIST)); eerst=deze=nieuw; firsttime = false; } else { deze->nextrecord=(MP3STRUCTLIST *)malloc(sizeof(MP3STRUCTLIST)); deze=deze->nextrecord; deze->nextrecord=nieuw; } total_records++; deze->number=total_records; current_record++; deze->length=length; strcpy(deze->name,title); strcpy(deze->path,filepath); return true; }
nieuw=new
deze=this
eerst=first
so when I want to add a nod, I call the function like this:
playlist.AddToList(000,lpofn.lpstrFile,lpofn.lpstr File);
lpofn is of the type OPENFILENAME
and lpofn.lpstrFile gets filled in by the GetOpenFileName function from the WIN32 API
but after the malloc, the value of lpofn.lpstrFile changes. I don't see how this is possible? does windows override a piece of memory that holds the OPENFILENAME data? and strangly, there is just one letter that changes in the filename
example: c:\My Documents\... changes to c:\My DoTuments\...
How is this possible????
is there some underlying memory bug somewhere that I'm not aware of.
I corrected the problem by adding a strcpy before the addtolist function, like this:
it works, but it doesn't give me an explination why this happens.Code:strcpy(buffer,lpofn.lpstrFile); playlist.AddToList(000,buffer,buffer);
and the lpofn.lpstrFile still changes and it isn't even part of the class it is a global variable.
anyone has an idea about this, why this happens?
thx
--Maes
BTW, if my function to add nodes contains bugs, or there are better ways to do it, let my know![]()



LinkBack URL
About LinkBacks



