Unicode problem (I think)

This is a discussion on Unicode problem (I think) within the Windows Programming forums, part of the Platform Specific Boards category; Hi, Is there a difference in getting the path of a file with GetOpenFileName or FindFirst and Findnext. Because I ...

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

    Unicode problem (I think)

    Hi,

    Is there a difference in getting the path of a file with GetOpenFileName or FindFirst and Findnext.

    Because I have this problem. when I get the filename (and path) with FindFirst and Findnext, I have no probelems. But when I use the common dialogbox GetOpenFileName I get an Unhandled exception.

    I can't find where he crashes by using breakpoints because I'm using threads (Actualy I don't see any problems why i shouldn't work, but it doesn't)
    when I leave the threads (I start two of them) out, everything works well.

    but when I try to find the error with breakpoints, he still gives the unhandled exeption before he stops at the first breakpoint.
    It looks like the error happens between the _beginthread() and the calling of the thread function (strange )
    here is some code:
    Code:
    /*this is in my main program
    arglist is a structure I use for passing the parameters*/
    
    arglist.kill=false;
    strcpy(arglist.text,name);
    _beginthread(FlashText,0,&arglist);//breakpoint
    
    
    /*this is th thread function*/
    void FlashText(PVOID pvoid)
    {
    	ARGLIST *parglist;
    	parglist=(ARGLIST *)pvoid;    //break point
    	char text[2000],buffer[40];
    	char display[40];
    	static char backup[2000];
    	int i,offset,len,j;
    
    	strcpy(text,parglist->text);
    	strcat(text," +++ ");
    	strcpy(backup,text);
    	len=strlen(text);
    	strncpy(display,text,33);
    	display[33]='\0';
    
    
    	offset=32;
    	j=0;
    
    	while(!parglist->kill)
    	{
    		SendDlgItemMessage(hmaindlg,IDC_INFO,WM_SETTEXT,0,(LPARAM)display);
    		for(i=0;i<31;i++)
    			buffer[i]=display[i+1];
    		buffer[31]=text[offset];
    		strcpy(display,buffer);
    		display[32]='\0';
    		if(offset==len-1)
    			offset=0;
    		else
    			offset++;
    		strcpy(text,backup);
    		Sleep(250);
    	}
    
    }
    //the error happens between the two breakpoints
    variable name is a char[MAX_PATH]
    When I copy the filepath that I got from Findfirst and findnext to name, everything works.
    But when I do the same with GetOpenFileName, it doesn't anymore


    please help me ::falls down on knees::
    Last edited by maes; 07-01-2002 at 02:37 PM.
    SVG is the future

  2. #2
    &TH of undefined behavior Fordy's Avatar
    Join Date
    Aug 2001
    Posts
    5,786
    Few obeservations.....

    Findfirst & Findnext are to my knowledge compiler dependant (There are FindFirstFile & FindNextFile APIs.....but I dont know if you are using them or not ).....

    I dont know if your return the file name or the full path.....

    The GetOpenFileName has in its return structure a member called lpstrFile (IE C:\windows\calc.exe) and a member called lpstrFileTitle (IE calc.exe). Could it be that you are passing the full path when you want the file and this is causing a buffer overrun?

    GetOpenFileName has an ASCII version and a Unicode version(GetOpenFileNameA & GetOpenFileNameW respectively) so I doubt that's your problem.......

    Also as a brief aside......the

    Code:
    while(!parglist->kill)
    could cause problems as 1 variable is accessed by 2 threads and trusting this value as a boolean test when constantly polling like that might cause problems....make sure the kill variable is marked "volitile" - theres a thread on this board from a few days ago which explains the problem - search for "volitile"

  3. #3
    Banned maes's Avatar
    Join Date
    Aug 2001
    Posts
    744
    thx Fordy for replying,

    I'm using this FindFirst and Findnext. I think it is the api function.
    ex: HANDLE hZoek = FindFirstFile(fldr, &FindFileData);

    I use this to find all the mp3 in a directory. But when I want to add a single file, everything works exept the two threads

    The GetOpenFileName has in its return structure a member called lpstrFile (IE C:\windows\calc.exe) and a member called lpstrFileTitle (IE calc.exe). Could it be that you are passing the full path when you want the file and this is causing a buffer overrun?
    I don't think this is the problem because I use lpofn.lpstrFile to play my mp3 file. and if I remove the threads, it plays just fine.
    I just noticed that lpofn.lpstrFileTitle is allways empty.


    >>could cause problems as 1 variable is accessed by 2 threads
    Actualy I'm controlling the other thread with a global variable and not parglist->kill. I know this isn"t the best way to do it but it should work I think

    here is the second thread: it almost doesn't use any variable that is comming from the main function
    only test.ReadMP3Tag(); but that isn't the problem because I call the same function before the thread and that isn't giving any problems
    Code:
    // In WM_COMMAND
    ...
    test.ReadMP3Tag();
    _beginthread(StartTime,0,0);//breakpoint
    ...
    
    //the thread function
    void StartTime(PVOID pvoid)
    {
    	int time=0;
    	char text[20],totaltime[10];
    
    	test.ReadMP3Tag();//breakpoint
    	strcpy(totaltime,test.mp3tag.Size);
    	while(test.play==true)
    	{
    		sprintf(text,"%d/%s",time,totaltime);
    		SendDlgItemMessage(listdialog,IDC_TIME,WM_SETTEXT,0,(LPARAM)text);
    		Sleep(1000);
    		time++;
    		if(resettime==true)
    		{
    			resettime=false;
    			time=0;
    		}
    	}
    }
    //resettime is a global bool
    Same story with the breakpoints. the error happens between the two of them
    SVG is the future

  4. #4
    Banned maes's Avatar
    Join Date
    Aug 2001
    Posts
    744
    I can't find the post about that volitile
    this is the only thing I find
    http://www.cprogramming.com/cboard/s...der=descending
    SVG is the future

  5. #5
    Banned maes's Avatar
    Join Date
    Aug 2001
    Posts
    744
    hahaha lol this thing is getting better by the minute

    this is what I have in my WM_COMMAND (I'm leaving some stuff out that isn't important)
    Code:
    WM_COMMAND
    ...
    case IDC_PLAY:
    _beginthread(StartTime,0,0);
    while(true);
    
    
    //the StartTime function
    void StartTime(PVOID pvoid)
    {
    
    }
    I added the while(true); so that he would never receive an other message and would not continue the program. I don't even play th mp3 file any more, just the thread.

    Is there a secret rule that you can not use GetOpenFileName and _beginthread in one program?


    I'm starting to get depressed here
    SVG is the future

  6. #6
    Registered User johnnie2's Avatar
    Join Date
    Aug 2001
    Posts
    186
    We're all assuming that the ARGLIST variable handled under WM_COMMAND has been defined outside the scope of just the window procedure. If this is not the case, you may be passing the address of a local variable to your thread function, leading to a memory exception when the variable expires after the _beginthread() call.
    "Optimal decisions, once made, do not need to be changed." - Robert Sedgewick, Algorithms in C

  7. #7
    Banned maes's Avatar
    Join Date
    Aug 2001
    Posts
    744
    Hi Johnnie2,

    arglist is made static so it keeps its value.

    And with the StartTime, I don't pass any arguments. the thread should stop immediatly.

    also, the debugger doesn't stop at a code line. This is where he stops:
    61442039 ???



    Please keep the ideas comming
    SVG is the future

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. problem with unicode
    By ssharish2005 in forum C Programming
    Replies: 6
    Last Post: 04-03-2006, 02:35 AM
  2. Laptop Problem
    By Boomba in forum Tech Board
    Replies: 1
    Last Post: 03-07-2006, 05:24 PM
  3. Replies: 5
    Last Post: 11-07-2005, 10:34 PM
  4. half ADT (nested struct) problem...
    By CyC|OpS in forum C Programming
    Replies: 1
    Last Post: 10-26-2002, 08:37 AM
  5. printing non-ASCII characters (in unicode)
    By dbaryl in forum C Programming
    Replies: 1
    Last Post: 10-25-2002, 01:00 PM

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