Thread: Unicode problem (I think)

  1. #1

    Unicode problem (I think)


    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:
    /*this is in my main program
    arglist is a structure I use for passing the parameters*/
    /*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;
    	strcat(text," +++ ");
    //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.

  2. #2
    &TH of undefined behavior Fordy's Avatar
    Join Date
    Aug 2001
    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

    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
    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
    // In WM_COMMAND
    //the thread function
    void StartTime(PVOID pvoid)
    	int time=0;
    	char text[20],totaltime[10];
    //resettime is a global bool
    Same story with the breakpoints. the error happens between the two of them

  4. #4
    I can't find the post about that volitile
    this is the only thing I find

  5. #5
    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)
    case IDC_PLAY:
    //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

  6. #6
    Registered User johnnie2's Avatar
    Join Date
    Aug 2001
    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
    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

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, 06:24 PM
  3. Replies: 5
    Last Post: 11-07-2005, 11: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