openfile error

This is a discussion on openfile error within the Windows Programming forums, part of the Platform Specific Boards category; When I compile this code with BC 4.5 compiler and click Cancel the program closes with an error. This seems ...

  1. #1
    Registered User
    Join Date
    Aug 2001
    Posts
    380

    openfile error

    When I compile this code with BC 4.5 compiler and click Cancel the program closes with an error. This seems to be cause from this line:
    ofn.lpstrFilter = "Wav Files (*.wav)\0*.wav\0All Files (*.*)\0*.*\0";

    Why would that line cause an error?

    Code:
    void getFile(void)
    {
    	OPENFILENAME ofn;
    	char szFileName[MAX_PATH] = "";
    	ZeroMemory(&ofn, sizeof(ofn));
    	ofn.lStructSize =  sizeof(ofn);
     //	ofn.hwndOwner =	 hwnd;
    //	ofn.lpstrFilter = "Text Files (*.txt)\0*.txt\0All Files\0*.*\0";
    	ofn.lpstrFilter = "Wav Files (*.wav)\0*.wav\0All Files (*.*)\0*.*\0";
    	ofn.lpstrFile = szFileName;
    	ofn.nMaxFile = MAX_PATH;
    	ofn.Flags = OFN_FILEMUSTEXIST | OFN_HIDEREADONLY;
      //	ofn.lpstrDefExt = "txt";
    	ofn.lpstrDefExt = "wav";
    
    	if(GetOpenFileName(&ofn))
    	{
     //		readFile(szFileName);
    	  SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),FGBLACK | BGWHITE);
    	  printf("Playing: ");
    	  SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),FGRED);
    	  printf(" %s", szFileName);
    	  sndPlaySound(szFileName,SND_ASYNC);
    	}
    }
    Don't you dare hit me on the head, you know I'm not normal.
    A Stooge Site
    Green Frog Software

  2. #2
    ejhdgdts
    Guest
    In a quoted string, is not the backslash character treated as an escape? Try replacing the \ with \\.

  3. #3
    Registered User 4point5's Avatar
    Join Date
    Oct 2002
    Posts
    44

    Cool

    You need to end that line with 2 null characters, so...

    ofn.lpstrFilter = "Wav Files (*.wav)\0*.wav\0All Files (*.*)\0*.*\0\0";

    Same thing goes for the other filter.
    Last edited by 4point5; 11-06-2002 at 07:50 AM.
    Don't try so hard. Just let it happen.

  4. #4
    Registered User
    Join Date
    Aug 2001
    Posts
    380
    You need to end that line with 2 null characters
    I tried your suggestion and still get the error. Also,
    I thought the compiler is suppose to add the second null character.
    Last edited by lambs4; 11-06-2002 at 12:11 PM.
    Don't you dare hit me on the head, you know I'm not normal.
    A Stooge Site
    Green Frog Software

  5. #5
    Registered User
    Join Date
    Apr 2002
    Posts
    1,571
    Try adding this line.

    ofn.nFilterIndex = 2;

    That tells it how many filters you have ( obviously ).

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Getting an error with OpenGL: collect2: ld returned 1 exit status
    By Lorgon Jortle in forum C++ Programming
    Replies: 6
    Last Post: 05-08-2009, 08:18 PM
  2. Making C DLL using MSVC++ 2005
    By chico1st in forum C Programming
    Replies: 26
    Last Post: 05-28-2008, 01:17 PM
  3. We Got _DEBUG Errors
    By Tonto in forum Windows Programming
    Replies: 5
    Last Post: 12-22-2006, 04:45 PM
  4. Dikumud
    By maxorator in forum C++ Programming
    Replies: 1
    Last Post: 10-01-2005, 06:39 AM
  5. Couple C questions :)
    By Divx in forum C Programming
    Replies: 5
    Last Post: 01-28-2003, 12:10 AM

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