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);
}
}