strange linked list problem

This is a discussion on strange linked list problem within the Windows Programming forums, part of the Platform Specific Boards category; Normaly I would post this in the C++ board, but I think the problem is windows related. I have class ...

  1. #1
    Banned maes's Avatar
    Join Date
    Aug 2001

    strange linked list problem

    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:
    bool CMP3LIST::AddToList(int length,char title[MAX_PATH],char filepath[MAX_PATH])
    	if (firsttime)
    		nieuw=(MP3STRUCTLIST *)malloc(sizeof(MP3STRUCTLIST));		
    		firsttime = false;
    		deze->nextrecord=(MP3STRUCTLIST *)malloc(sizeof(MP3STRUCTLIST));  
    	return true;
    some words are dutch, I'll translate to clearefy (sp?)

    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.
    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?



    BTW, if my function to add nodes contains bugs, or there are better ways to do it, let my know
    Last edited by maes; 09-06-2003 at 10:31 AM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Following CTools
    By EstateMatt in forum C Programming
    Replies: 5
    Last Post: 06-26-2008, 11:10 AM
  2. Replies: 6
    Last Post: 03-02-2005, 02:45 AM
  3. problem with structures and linked list
    By Gkitty in forum C Programming
    Replies: 6
    Last Post: 12-12-2002, 06:40 PM
  4. Linked List problem
    By spec85 in forum C Programming
    Replies: 1
    Last Post: 06-14-2002, 04:58 AM
  5. singly linked list
    By clarinetster in forum C Programming
    Replies: 2
    Last Post: 08-26-2001, 11:21 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21