Assumption: The filename contains no more than 12 characters.

If your operating system supports long filenames, 12-character buffers might not have enough space for all the characters in the filename. Consider the following code snippet, in which the buffer is assumed to be 12 characters long:

char szFile [12] = "\0";

// Fill out the OPENFILENAME structure to support a template and a hook.
OpenFileName.lStructSize = sizeof (OPENFILENAME);
OpenFileName.hwndOwner = hWnd;
OpenFileName.hInstance = g_hInst;
OpenFileName.lpstrFilter = NULL;
OpenFileName.lpstrCustomFilter = NULL;
OpenFileName.nMaxCustFilter = 0;
OpenFileName.nFilterIndex = 0;
OpenFileName.lpstrFile = szFile;
OpenFileName.nMaxFile = sizeof (szFile);
OpenFileName.lpstrFileTitle = NULL;
OpenFileName.nMaxFileTitle = 0;
OpenFileName.lpstrInitialDir = NULL;
OpenFileName.lpstrTitle = "Open a File";
OpenFileName.nFileOffset = 0;
OpenFileName.nFileExtension = 0;
OpenFileName.lpstrDefExt = NULL;
OpenFileName.lCustData = NULL;
OpenFileName.lpfnHook = ComDlg32DlgProc;
OpenFileName.lpTemplateName = MAKEINTRESOURCE (IDD_COMDLG32);
OpenFileName.Flags = OFN_SHOWHELP | OFN_EXPLORER |
OFN_ENABLEHOOK | OFN_ENABLETEMPLATE;

// Call the common dialog function.
if (GetOpenFileName (&OpenFileName))
{
§
}
else
{
ProcessCDError (CommDlgExtendedError (), hWnd);
return FALSE;
}

If the user enters a filename that contains more than 12 characters, the Open common dialog procedure returns an error of FNERR_BUFFERTOOSMALL, saving you from a nasty trap. But the buffer size is not the only problem. If you are doing your own file parsing, and if you accept only the first 12 characters in a filename, you could open the wrong file. For instance, imagine that a user enters the filename Marketing Report and that the current directory contains files named Marketing Report and Marketing Salaries. If your application accepts only the first 8 characters of a filename and assumes an extension, which file will the application open?